【发布时间】:2014-08-09 01:21:21
【问题描述】:
我正在使用以下代码示例将 Instagram 照片分享功能添加到我的 iPhone 应用中:
我的代码示例和我的应用程序也有同样的问题。 “打开方式”菜单与 Instagram、iPhoto 等一起出现,但推送时没有打开任何应用程序。你们中的一个天才可以看看代码示例并告诉我我错过了什么吗?谢谢!
这是.h代码:
@interface ViewController : UIViewController<UIDocumentInteractionControllerDelegate>{
IBOutlet UIImageView *imageView;
}
@property(nonatomic,retain)UIDocumentInteractionController *docFile;
@property (nonatomic, retain) UIDocumentInteractionController *dic;
-(IBAction)saveToInstagram:(id)sender;
在 .m 代码中:
@synthesize docFile = _docFile;
-(IBAction)saveToInstagram:(id)sender {
CGRect rect = CGRectMake(0 ,0 , 0, 0);
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIGraphicsEndImageContext();
NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/test.ig"];
NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@", jpgPath]];
self.docFile.UTI = @"com.instagram.photo";
self.docFile = [self setupControllerWithURL:igImageHookFile usingDelegate:self];
self.docFile=[UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
[self.docFile presentOpenInMenuFromRect: rect inView: self.view animated: YES ];
NSURL *instagramURL = [NSURL URLWithString:@"instagram://media?id=MEDIA_ID"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
[self.docFile presentOpenInMenuFromRect: rect inView: self.view animated: YES ];
}
else {
NSLog(@"No Instagram Found");
}
}
- (UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL usingDelegate: (id <UIDocumentInteractionControllerDelegate>) interactionDelegate {
UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL: fileURL];
interactionController.delegate = interactionDelegate;
return interactionController;
}
谢谢。
【问题讨论】:
-
我将项目中的代码添加到原始帖子中。谢谢。
标签: ios objective-c instagram