Crash when you click "Open on Instagram" - goal c

My application crashes when I click "Open on Instagram." iOS7

My code: .h file:

@property(nonatomic, retain)     UIDocumentInteractionController* docController;

And in the .m file:

 NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/test.ig"];
 NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@", jpgPath]];

_docController = [UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];//[NSURL fileURLWithPath:imagePath]];
_docController.delegate=self;
_docController.UTI = @"com.instagram.exclusivegram";
[_docController presentOpenInMenuFromRect:appDelegate.window.rootViewController.view.frame inView:appDelegate.window.rootViewController.view animated:YES];

Also I used:

CGRect rect = CGRectMake(0 ,0 , 0, 0);

UIGraphicsBeginImageContextWithOptions(appDelegate.window.rootViewController.view.bounds.size, appDelegate.window.rootViewController.view.opaque, 0.0);
[appDelegate.window.rootViewController.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIGraphicsEndImageContext();
NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/test.ig"];

NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@", jpgPath]];

_docfile.UTI = @"com.instagram.photo";
_docfile = [self setupControllerWithURL:igImageHookFile usingDelegate:self];
_docfile=[UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
[_docfile presentOpenInMenuFromRect: rect inView: appDelegate.window.rootViewController.view animated: YES ];
NSURL *instagramURL = [NSURL URLWithString:@"instagram://media?id=MEDIA_ID"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
    [_docfile presentOpenInMenuFromRect: rect inView: appDelegate.window.rootViewController.view animated: YES ];
}
else {
    NSLog(@"No Instagram Found");
}

also:

- (UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL usingDelegate: (id) interactionDelegate {

    UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL: fileURL];
   interactionController.delegate = interactionDelegate;

   return interactionController;

}

stack trace:

Thread 1, Queue : com.apple.main-thread
#0  0x37c2b636 in objc_msgSend ()
#1  0x300f7442 in -[_UIOpenWithAppActivity performActivity] ()
#2  0x2feadad0 in -[UIActivityViewController _executeActivity] ()
#3  0x2fead4b8 in -[UIActivityViewController _performActivity:] ()
#4  0x300f7b0a in -[_UIDocumentActivityViewController _performActivity:] ()
#5  0x2fead068 in -[UIActivityGroupViewController collectionView:didSelectItemAtIndexPath:] ()
#6  0x2feacc8e in -[UICollectionView _userSelectItemAtIndexPath:] ()
#7  0x2feac974 in -[UICollectionView touchesEnded:withEvent:] ()
#8  0x2fe17794 in forwardTouchMethod ()
#9  0x2fe17794 in forwardTouchMethod ()
#10 0x2fcc5720 in -[UIWindow _sendTouchesForEvent:] ()
#11 0x2fcc06ea in -[UIWindow sendEvent:] ()
#12 0x2fc958ec in -[UIApplication sendEvent:] ()
#13 0x2fc93f96 in _UIApplicationHandleEventQueue ()
#14 0x2d44025a in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ ()
#15 0x2d43f72a in __CFRunLoopDoSources0 ()
#16 0x2d43df1e in __CFRunLoopRun ()
#17 0x2d3a8f4e in CFRunLoopRunSpecific ()
#18 0x2d3a8d32 in CFRunLoopRunInMode ()
#19 0x322ad662 in GSEventRunModal ()
#20 0x2fcf416c in UIApplicationMain ()
#21 0x001009ce in main at /Epic MAR/samples/Epic MAR/ImageTargets/main.m:13
#22 0x00100958 in start ()

After creating an exception breakpoint, a message appears in the log:

-[__NSCFSet _openDocumentWithApplication:]: unrecognized selector sent to instance 0xb95d00 

What is the problem?

Also, do I need to integrate with Instagram ?, make an app and set the appID as Facebook?

Thank,

+4
source share

Source: https://habr.com/ru/post/1542809/


All Articles