2016-03-02 59 views
0

我曾嘗試這個代碼,但它顯示錯誤,如如何在本地應用程序ios 9.2上分享instagram上的圖像?

警告:試圖提出< _UIDocumentActivityViewController: 0x16acdc00>上這已經是 呈現< _UIDocumentActivityViewController:0x16ae4800>

如何解決這個問題?

-(IBAction)saveToInstagram:(id)sender { 


     CGRect rect = CGRectMake(0 ,0 , 0, 0); 
     NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.ig"]; 

     NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@", jpgPath]]; 
     NSLog(@"JPG path %@", jpgPath); 
     NSLog(@"URL Path %@", igImageHookFile); 
     self.docFile.UTI = @"com.instagram.photo"; 
     self.docFile = [self setupControllerWithURL:igImageHookFile usingDelegate:self]; 
     self.docFile=[UIDocumentInteractionController interactionControllerWithURL:igImageHookFile]; 
     [self.docFile presentOpenInMenuFromRect: rect inView: self.view animated: YES ]; 
     NSURL *instagramURL = [NSURL URLWithString:@"instagram://media?id=MEDIA_ID"]; 
     if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) { 
      [self.docFile presentOpenInMenuFromRect: rect inView: self.view animated: YES ]; 
     } 
     else { 
      NSLog(@"No Instagram Found"); 
     } 



} 
- (UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL usingDelegate: (id <UIDocumentInteractionControllerDelegate>) interactionDelegate { 
    UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL: fileURL]; 
    interactionController.delegate = interactionDelegate; 
    return interactionController; 
} 

- (void)documentInteractionControllerWillPresentOpenInMenu:(UIDocumentInteractionController *)controller { 

} 

回答

2

的問題是,雖然第一DOCFILE正在呈現你的態度來提供第二個

// First presentation 
[self.docFile presentOpenInMenuFromRect: rect inView: self.view animated: YES ]; 

NSURL *instagramURL = [NSURL URLWithString:@"instagram://media?id=MEDIA_ID"]; 
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) { 

     // Second presentation 
     [self.docFile presentOpenInMenuFromRect: rect inView: self.view animated: YES ]; 
} 

我真的不明白,爲什麼你需要用同樣的方法兩次,但如果你真的這樣做,那麼第一次使用動畫:NO。我會建議某種完成代碼塊,但似乎沒有這樣的方法UIDocumentInteractionController

0

不要忘記添加<string>instagram</string>在你的plist數組中鍵入:LSApplicationQueriesSchemes。

@property (nonatomic, strong) UIDocumentInteractionController *docIC;   

- (void)sharePhoto:(UIImage *)image caption:(NSString *)caption 
{ 
    NSURL *instagramURL = [NSURL URLWithString:@"instagram://"]; 
    if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) 
    { 
     NSString *docDir = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; 
     NSString *imgPath = [docDir stringByAppendingPathComponent:@"Image.igo"]; 
     NSData *data = UIImageJPEGRepresentation(image, 1.0); 
     [data writeToFile:imgPath atomically:YES]; 


     NSURL *igImageHookFile = [NSURL fileURLWithPath:imgPath]; 
     self.docIC = [UIDocumentInteractionController interactionControllerWithURL:igImageHookFile]; 
     [self.docIC setDelegate:self]; 
     [self.docIC setUTI:@"com.instagram.exclusivegram"]; 

     // Subject 
     [self.docIC setName:[TUtil appName]]; 

     //http://developers.instagram.com/post/125972775561/removing-pre-filled-captions-from-mobile-sharing 
     //self.docIC.annotation = [NSDictionary dictionaryWithObjectsAndKeys:caption, @"InstagramCaption", nil]; 

     [self.docIC presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES]; 
    } 
    else 
    { 
     NSString *iTunesLink = @"itms-apps://itunes.apple.com/app/id389801252?mt=8"; 
     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]]; 
    } 
} 
相關問題