【问题标题】:How to share image from my apps to the Instagram如何将我的应用程序中的图像分享到 Instagram
【发布时间】:2017-07-19 03:22:34
【问题描述】:

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

【问题讨论】:

  • 我在没有集成的情况下完成了目标 c 如果你愿意,我可以分享该代码
  • 如果你能和我分享我很高兴...
  • @NurAinMdIsa,请查看附加的 URL - stackoverflow.com/questions/36406515/…

标签: ios iphone swift url instagram


【解决方案1】:

我曾在 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];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-08
    • 1970-01-01
    • 1970-01-01
    • 2013-04-29
    • 1970-01-01
    • 2013-12-16
    相关资源
    最近更新 更多