简体   繁体   English

使用任何人sdk或PHPhotolibrary在Instagram上分享图像?

[英]Sharing Image on instagram using anyone sdk Or PHPhotolibrary?

I want to share the imageurl to instagram and i know very well it is possible by uidocumentinteraction controller. 我想将图像分享到Instagram,我很清楚它可以通过uidocumentinteraction控制器实现。

But for my understanding there is no official sdk in instagram to sharing the image. 但据我了解,Instagram中没有官方sdk来共享图像。 So my question is without using uidocumentinteraction is it possible to share the image using sdk or PHPhotolibrary ? 所以我的问题是没有使用uidocumentinteraction是否可以使用sdk或PHPhotolibrary共享图像?

Finally i found a solution. 最后我找到了解决方案。

UIImage *getImage=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imgURL]]];
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
    PHAssetChangeRequest * assetReq = [PHAssetChangeRequest creationRequestForAssetFromImage:getImage];
    NSString* localId = [[assetReq placeholderForCreatedAsset] localIdentifier];
    NSString *escapedString = [localId 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.");
    }


} completionHandler:^(BOOL success, NSError *error) {
    if (!success){
        NSLog(@"%@",error);
    }
}];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM