我有以下代码可以将照片发布到 Instagram:
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES);
NSString* homePath = [paths objectAtIndex:0];
NSString* basePath = @"integration/instagram";
NSString* tmpFileName = @"jumpto.ig";
NSString* dirPath = [NSString stringWithFormat:@"%@/%@", homePath, basePath];
NSString* docPath = [NSString stringWithFormat:@"%@/%@", dirPath, tmpFileName];
//clear it out and make it fresh
[[NSFileManager defaultManager] removeItemAtPath:docPath error:nil];
if ([[NSFileManager defaultManager] createDirectoryAtPath:dirPath withIntermediateDirectories:YES attributes:nil error:nil]) {
NSData* imgData = [self generateImageData:img];
[[NSFileManager defaultManager] createFileAtPath:docPath contents:imgData attributes:nil];
NSURL* url = [NSURL fileURLWithPath:docPath isDirectory:NO ];
NSURL *instagramURL = [NSURL URLWithString:@"instagram://camera"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
//imageToUpload is a file path with .ig file extension
self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:url];
self.documentInteractionController.UTI = @"com.instagram.exclusivegram";
self.documentInteractionController.delegate = self;
self.documentInteractionController.annotation = [NSDictionary dictionaryWithObject:@"Caption Test" forKey:@"InstagramCaption"];
[self.documentInteractionController presentOptionsMenuFromBarButtonItem:self.navigationItem.rightBarButtonItem animated:YES];
}
}
问题是,当我打开弹出窗口时,我看到了其他服务,例如 facebook/twitter/mail/print/assign to contact/copy/etc。如何使我只有一个选项,即在 Instagram 中打开?