I am doing the apps for online seller using swift 3. Then this apps could share the items into the social media. But I have a problem to sharing to the Instagram. Every apps has their own url scheme to open it right? Can you guys help me, what is the Instagram url scheme to directly open the crop page in the Instagram?
Asked
Active
Viewed 907 times
0
-
I had done in objective c without integration If you want I can share that code – iOS Geek Jul 19 '17 at 03:42
-
I am glad if you can share with me... – Nur Ain Md Isa Jul 19 '17 at 03:54
-
@NurAinMdIsa, Please review attached URL - https://stackoverflow.com/questions/36406515/post-uiimage-to-instagram-using-swift-similar-to-slcomposeviewcontroller – Renish Dadhaniya Jul 19 '17 at 06:34
1 Answers
1
I had used photos framework in Obj c to get an image in 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];
}
}
}
Just call this function when you want to share an image to Instagram
[self savePostsPhotoBeforeSharing];

iOS Geek
- 4,825
- 1
- 9
- 30