gpt4 book ai didi

ios - 如何将图像从我的应用程序分享到 Instagram

转载 作者:行者123 更新时间:2023-11-28 15:26:11 24 4
gpt4 key购买 nike

我正在使用 swift 3 为在线卖家开发应用程序。然后该应用程序可以将商品分享到社交媒体中。但是我在分享到 Instagram 时遇到了问题。每个应用程序都有自己的 url 方案来打开它,对吗?你们能帮帮我吗,直接在 Instagram 中打开裁剪页面的 Instagram url 方案是什么?

最佳答案

我曾使用 Obj c 中的照片框架在 Asset 中获取图像

-(void)savePostsPhotoBeforeSharing {
UIImageWriteToSavedPhotosAlbum(choosenImage, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL); //Choosen image is image that you need to send on Instagram
}


- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo: (void *) contextInfo; {
[self sharePostOnInstagram]; // this function save image .io format and check if any error exist or not
}


-(void)sharePostOnInstagram. //this will share your selected image on Instagram through its installed app
{
PHFetchOptions *fetchOptions = [PHFetchOptions new];
fetchOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO],];
__block PHAsset *assetToShare;
PHFetchResult *result = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:fetchOptions];
[result enumerateObjectsUsingBlock:^(PHAsset *asset, NSUInteger idx, BOOL *stop) {
assetToShare = asset;
}];
if([assetToShare isKindOfClass:[PHAsset class]])
{
NSString *localIdentifier = assetToShare.localIdentifier;
NSString *urlString = [NSString stringWithFormat:@"instagram://library?LocalIdentifier=%@",localIdentifier];
NSURL *instagramURL = [NSURL URLWithString:urlString];
if ([[UIApplication sharedApplication] canOpenURL: instagramURL]) {
[[UIApplication sharedApplication] openURL: instagramURL];
} else {
UIAlertController *removedSuccessFullyAlert = [UIAlertController alertControllerWithTitle:@"Error!!" message:@"No Instagram Application Found!" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *firstAction = [UIAlertAction actionWithTitle:@"Okay" style:UIAlertActionStyleDefault handler:nil];
[removedSuccessFullyAlert addAction:firstAction];
[self presentViewController:removedSuccessFullyAlert animated:YES completion:nil];
}
}
}

当你想分享图片到 Instagram 时调用这个函数就可以了

[self savePostsPhotoBeforeSharing];

关于ios - 如何将图像从我的应用程序分享到 Instagram,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45180414/

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