在将图像分享到 Instagram 后,有没有办法重新打开我的应用程序?
我分享到 Instagram 的代码:
[Utils saveImage:self.pickedImage withName:@"image.igo"];
CGRect rect = CGRectMake(0 ,0 , 0, 0);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *imagePath = [documentsDirectory stringByAppendingPathComponent:@"image.igo"];
NSURL *igImageHookFile = [NSURL fileURLWithPath:imagePath];
self.docFile=[UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
self.docFile.UTI = @"com.instagram.exclusivegram";
self.docFile.annotation = [NSDictionary dictionaryWithObject: self.descrText forKey:@"InstagramCaption"];
NSURL *instagramURL = [NSURL URLWithString:@"instagram://media?id=MEDIA_ID"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
[self.docFile presentOpenInMenuFromRect: rect inView: self.view animated: YES ];
}
else {
[Utils simpleAlertWithTitle:LOC(@"You have not Instagram app in device.") message:nil];
}
现在打开 Instagram 应用程序并打开共享屏幕。 我想在点击 Instagram 应用中的“分享”按钮后返回到我的应用程序,并获取有关共享照片(userId、photoUrl 等)的一些回调。
这可能吗?
谢谢。
最佳答案
Hope this answer will resolve your query. This will directly opens library folder in Instagram instead of Camera.
NSURL *instagramURL = [NSURL URLWithString:@"instagram://app"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL])
{
NSURL *videoFilePath = [NSURL URLWithString:[NSString stringWithFormat:@"%@",[request downloadDestinationPath]]]; // Your local path to the video
NSString *caption = @"Some Preloaded Caption";
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeVideoAtPathToSavedPhotosAlbum:videoFilePath completionBlock:^(NSURL *assetURL, NSError *error) {
NSString *escapedString = [self urlencodedString:videoFilePath.absoluteString];
NSString *escapedCaption = [self urlencodedString:caption];
NSURL *instagramURL = [NSURL URLWithString:[NSString stringWithFormat:@"instagram://library?AssetPath=%@&InstagramCaption=%@",escapedString,escapedCaption]];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
[[UIApplication sharedApplication] openURL:instagramURL];
}
}];
关于iOS SDK 和 Instagram,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21286044/