我之前在Obj-C中实现了这个,但是无法使它在swift上运行。我希望能够分享照片到Instagram以及其他标准应用程序。
- (IBAction)thirdOne:(id)sender {
NSDictionary *fruitParams = [NSDictionary dictionaryWithObjectsAndKeys:self.fruitName, @"Fruit Name",nil];
NSString* imagePath = [NSString stringWithFormat:@"%@/instagramShare.igo", [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]];
[[NSFileManager defaultManager] removeItemAtPath:imagePath error:nil];
UIImage *instagramImage = self.image;
[UIImagePNGRepresentation(instagramImage) writeToFile:imagePath atomically:YES];
self.dic=[UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:imagePath]];
self.dic.UTI = @"com.instagram.exclusivegram";
[self.dic presentOpenInMenuFromRect: self.view.frame inView:self.view animated:YES ];
}
按钮的外观如下:
这就是单击按钮时发生的情况: