1

UIDocumentInteractionControllerおよびUIActivityViewControllerは、イメージを他のネットワークに共有するための両方のメニューを表示します。 Instagramを叩いた後、あなたはアプリを離れることなくInstagramに投稿できる素敵なモーダルが表示されます。私の質問は、メニューを表示せずにモーダルを自動的にどのように表示するのですか?UIDocumentInteractionControllerまたはUIActivityViewControllerでInstagramを自動的に選択

このアプリはSoundsと呼ばれているため、可能性があると私は知っていますが、どのようにして完了したかに関するオンラインのドキュメントは見つかりません。ここでは、メニューを示し、私が持っている現在のコードは次のとおりです。

NSString *documentDirectory=[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; 
    NSString *saveImagePath=[documentDirectory stringByAppendingPathComponent:@"Image.ig"]; 
    NSData *imageData=UIImagePNGRepresentation(cardImage); 
    [imageData writeToFile:saveImagePath atomically:YES]; 
    NSURL *imageURL=[NSURL fileURLWithPath:saveImagePath]; 

    UIDocumentInteractionController *docController = [UIDocumentInteractionController interactionControllerWithURL:imageURL]; 
    docController.UTI = @"com.instagram.exclusivegram"; 
    docController = [self setupControllerWithURL:imageURL usingDelegate:self]; 
    [docController presentOpenInMenuFromRect:CGRectMake(1, 1, 1, 1) inView:self.view animated:YES]; 

ここでメニューです: 1

ここで私が自動的に表示したいものです。

2]

+0

あなたは、問題への解決策を見つけますか?私は同じ問題を抱えている。 –

答えて

0

を他を削除するにはアプリケーションが表示されないようにするには(コードをひっくり返すだけ):

docController.UTI = @"com.instagram.exclusivegram"; 
docController = [self setupControllerWithURL:imageURL usingDelegate:self]; 

docControllerオブジェクトをオーバーライドした後に.UTI変数が設定されるようにします。

編集:情報を記入して共有する準備が整った状態でInstagramアプリケーションを開いてみようとしている場合、iPhoneフックhereをチェックアウトしてください。

+0

本当に具体的なリクエストだとわかっていますが、iPhoneのフックは私たちが探しているものではありません。我々は、アプリケーションを残したくない、我々はそのモーダルを自動的にプルアップしたい。このアプリSounds(https://www.sounds.am/)はそれを行います。 Instagramボタンをクリックすると、すぐにそのモーダルが表示されます。どのようにそれが行われている任意のアイデア? – evenodd

+0

これはまさに私が過去2日間のグーグルで行ったことです。あなたは答えを見つけましたか?私はそれが可能であることを知っているので、アプリがこれを行うのを見た。 –

0

私はあなただけあなたは限りがあるのInstagramを表示するUIActivityViewControllerを使用することができます

SocialShare.shared.postImageToInstagram(UIImage(named: "1")) 
2

を呼び出す使用したいんがどこかのInstagramに

import UIKit 
import Photos 

class SocialShare: NSObject { 
    static let shared = SocialShare() 

    func postImageToInstagram(image: UIImage) { 
     UIImageWriteToSavedPhotosAlbum(image, self, #selector(SocialShare.image(_:didFinishSavingWithError:contextInfo:)), nil) 
    } 
    func image(image: UIImage, didFinishSavingWithError error: NSError?, contextInfo:UnsafePointer<Void>) { 
     if error != nil { 
      print(error) 
     } 

     let fetchOptions = PHFetchOptions() 
     fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)] 
     let fetchResult = PHAsset.fetchAssetsWithMediaType(.Image, options: fetchOptions) 
     if let lastAsset = fetchResult.firstObject as? PHAsset { 
      let localIdentifier = lastAsset.localIdentifier 
      let u = "instagram://library?LocalIdentifier=" + localIdentifier 
      UIApplication.sharedApplication().openURL(NSURL(string: u)!) 
     } 
    } 
} 

を画像を共有するために使用されていないコードアクティビティアイテム内のUIImageだけです。 テキスト、URLなどの項目を追加しても表示されません。 これはInstagramによる悪い制限です。そのよう

NSMutableArray *items = [NSMutableArray array]; 
[items addObject:[UIImage ...]]; 

// show view 
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:items 
                      applicationActivities:nil]; 
[vc presentViewController:activityVC animated:YES completion:nil]; 
0

ここZuhairの答えを実装スウィフト4クラスです。

import Foundation 
import Photos 

class InstagramSharer: NSObject { 
    static let shared = InstagramSharer() 

    func post(image: UIImage) { 
     UIImageWriteToSavedPhotosAlbum(image, self, #selector(image(image:didFinishSavingWithError:contextInfo:)), nil) 
    } 

    @objc 
    private func image(image: UIImage, didFinishSavingWithError error: NSError?, contextInfo: UnsafeRawPointer) { 
     guard error == nil else { 
      return 
     } 

     let fetchOptions = PHFetchOptions() 
     fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)] 
     let fetchResult = PHAsset.fetchAssets(with: .image, options: fetchOptions) 

     if let lastAsset = fetchResult.firstObject { 
      let localIdentifier = lastAsset.localIdentifier 
      let url = "instagram://library?LocalIdentifier=" + localIdentifier 
      UIApplication.shared.openURL(URL(string: url)!) 
     } 
    } 
} 

使用

InstagramSharer.shared.post(image: #YOUR_IMAGE#) 
関連する問題