我有以下代碼張貼照片到Instagram的:在UIDocumentController
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的/郵件/打印/分配給聯繫人/複製/等。我如何做到這一點,我只有一個在Instagram上打開的選項?
如果您只想支持特定服務(Instagram),那麼爲什麼要使用'UIDocumentInteractionController'?提供您自己的簡單用戶界面(可能是警報或操作表)。如果用戶說「是」,那麼您可以使用正確的URL直接啓動Instagram。 – rmaddy 2013-02-10 17:46:36
爲什麼你不能禁用其他選項? – adit 2013-02-10 17:47:33
因爲你不行。這沒有API。 「UIDocumentInteractionController」的意義在於向用戶展示支持特定文件/ UTI的所有可能的應用程序。 – rmaddy 2013-02-10 17:48:49