我正在使用swift 3为在线卖家做的应用程序。然后这个应用程序可以将这些项目共享到社交媒体中。但我有一个问题,分享到Instagram。每个应用都有自己的网址方案来打开它吗?你们可以帮助我吗,Instagram的网址方案是什么直接打开Instagram的裁剪页面?
答案 0 :(得分:1)
我曾使用Obj c中的照片框架来获取资产
中的图像-(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];