繁体   English   中英

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

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

我想将图像分享到Instagram,我很清楚它可以通过uidocumentinteraction控制器实现。

但据我了解,Instagram中没有官方sdk来共享图像。 所以我的问题是没有使用uidocumentinteraction是否可以使用sdk或PHPhotolibrary共享图像?

最后我找到了解决方案。

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