gpt4 book ai didi

ios - 如何将带有 URL Shema 的 UIImage 分享到 Instagram 应用程序?

转载 作者:行者123 更新时间:2023-11-29 12:21:53 25 4
gpt4 key购买 nike

我有我创建的图像,我想通过 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 Schema 将 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.");
}
}];

关于ios - 如何将带有 URL Shema 的 UIImage 分享到 Instagram 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30399524/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com