我有创建的图像,想通过instagram应用程序共享它,该怎么办?
- (IBAction)instagramShareTapped:(UIButton *)sender {
UIImage *img = self.myImage;
NSURL *instagramURL = [NSURL URLWithString:[NSString stringWithFormat:@"instagram://**WHAT_SHOULD_I_PUT_HERE?**]];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
[[UIApplication sharedApplication] openURL:instagramURL];
}
}
最佳答案
这是我可以使用URL架构将UIImage共享到Instagram的方法:
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
UIImage *image = // your image that you want share
[library writeImageToSavedPhotosAlbum:image.CGImage orientation:(ALAssetOrientation)image.imageOrientation completionBlock:^(NSURL *assetURL, NSError *error) {
NSString *escapedString = [assetURL.absoluteString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet alphanumericCharacterSet]];
NSURL *instagramURL = [NSURL URLWithString:[NSString stringWithFormat:@"instagram://library?AssetPath=%@", escapedString]];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
[[UIApplication sharedApplication] openURL:instagramURL];
} else {
NSLog(@"Instagram app not found.");
}
}];