2014-12-05 57 views
1

我使用UIDocumentInteractionController在Instagram上分享照片,我可以打開操作表(我不知道應該怎麼稱呼),但是當我點擊Open in Instagram它只是崩潰和消息將是,消息發送到釋放實例,同時使用UIDocumentInteractionController的Instagram

*** - [UIDocumentInteractionController _openDocumentWithApplication:]:消息發送到釋放實例0x1743762c0

對於一個音符,我使用ARC,和也創造了UIDocumentInteractionController的強大財產。

新增保有財產UIDocumentInteractionController

@property (nonatomic, retain) UIDocumentInteractionController *docController; 

這是分享代碼,

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

- (void) instagramShare { 
    NSURL *instagramURL = [NSURL URLWithString:@"instagram://"]; 
    if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) 
    { 
     NSString *filePath = [self saveAsIgoFile]; 
     NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@", filePath]]; 
     CGRect rect = CGRectMake(0, 0, 0, 0); 
     self.docController = [self setupControllerWithURL:igImageHookFile usingDelegate:(id)_view]; 
     self.docController.UTI = @"com.instagram.photo"; 
     self.docController.annotation = [NSDictionary dictionaryWithObject:_titleToShare forKey:@"InstagramCaption"]; 
     [self.docController presentOpenInMenuFromRect:rect inView:_view.parentViewController.view animated:YES]; 
    } 
    else 
    { 
     if(_block) { 
      _block (_shareType, NO, @"Instagram not installed in this device!\nTo share photo/video please install Instagram application."); 
     } 
    } 
} 

我在一個班,名爲 「ShareClass」 的NSObject其子這樣做。

請注意,我已經檢查了一些同樣問題的答案,但是它們是針對非ARC的,我也嘗試將屬性設置爲強或保留兩者。這似乎並不奏效。

+0

'interactionDelegate'在這裏如何使用?你正在實現'documentInteractionControllerViewControllerForPreview:controller '委託方法嗎? – sleepwalkerfx 2014-12-05 09:04:23

+0

這段代碼工作正常,除非我沒有在塊中使用它自定義類。 – Hemang 2014-12-05 09:05:47

+0

上面的委託方法必須返回您的呈現ViewController。你做得對嗎? – sleepwalkerfx 2014-12-05 09:07:07

回答

1

最後,我通過自定義類的共享實例對它進行了整理,該實例將保留在應用程序中,並且不會釋放任何實例。不確定不好或好,但作品像魅力。^_O

相關問題