【问题标题】:How to share UIImage with URL Shema to Instagram app?如何将带有 URL Shema 的 UIImage 共享到 Instagram 应用程序?
【发布时间】:2015-05-22 14:35:53
【问题描述】:

我有我创建的图像,我想通过 instagram 应用分享它,我应该怎么做?

 - (IBAction)instagramShareTapped:(UIButton *)sender {
   UIImage *img = self.myImage;
   NSURL *instagramURL = [NSURL URLWithString:[NSString stringWithFormat:@"instagram://**WHAT_SHOULD_I_PUT_HERE?**]];
   if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
     [[UIApplication sharedApplication] openURL:instagramURL];
   }
}

【问题讨论】:

    标签: ios objective-c uiimage instagram instagram-api


    【解决方案1】:

    以下是我如何使用 URL Schema 将 UIImage 共享到 Instagram:

        ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
        UIImage *image = // your image that you want share
        [library writeImageToSavedPhotosAlbum:image.CGImage orientation:(ALAssetOrientation)image.imageOrientation completionBlock:^(NSURL *assetURL, NSError *error) {
    
          NSString *escapedString = [assetURL.absoluteString 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.");
          }
        }];
    

    【讨论】:

    【解决方案2】:

    发现于instagram documentation

    文档交互

    如果您的应用程序创建了照片,并且您希望您的用户使用 Instagram 分享这些照片,您可以使用 Document Interaction API 在 Instagram 的分享流程中打开您的照片。

    您必须首先将文件保存为 PNG 或 JPEG(首选)格式,并使用文件扩展名“.ig”。使用 iOS 文档交互 API,您可以触发 Instagram 打开照片。我们的文档交互 UTI 的标识符是 com.instagram.photo,它符合 public/jpeg 和 public/png UTI。有关详细信息,请参阅 Apple 文档文章:预览和打开文件和 UIDocumentInteractionController 类参考。

    或者,如果您只想在应用程序列表中显示 Instagram(而不是 Instagram 以及任何其他符合公共/jpeg 标准的应用程序),您可以指定扩展类 igo,其类型为 com.instagram.exclusivegram。

    触发后,Instagram 将立即向用户展示我们的过滤屏幕。该图像已为 Instagram 预加载和调整大小。为获得最佳效果,Instagram 更喜欢打开 640 像素 x 640 像素正方形的 JPEG。如果图片较大,则会动态调整大小。

    要在您的照片中包含预填充的标题,您可以将文档交互请求中的注释属性设置为包含键“InstagramCaption”下的 NSString 的 NSDictionary。此功能适用于 Instagram 2.1 及更高版本。

    【讨论】:

    • 问题是关于使用 URL Schema 共享图像而不是使用 Document Interaction API。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-13
    • 1970-01-01
    • 2018-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多