Swift开发

分享图片到instagram

2018-04-19  本文已影响0人  CN_HarrySun

1. 需求:将app中的图片分享到instagram

需求是分享图片到instagram,但是官方没有提供进入分享页的url,不过官方API上推荐了另一种方式:使用系统分享Document Interaction

instagramAPI提供的几种跳转:
URL OPENS
app The Instagram app
camera The camera (or photo library on non-camera devices)
media?id=MEDIA_ID Media with this ID
user?username=USERNAME User with this username
location?id=LOCATION_ID Location feed for this location ID
tag?name=TAG Tag feed for this tag

2. 问题:使用系统分享时遇到问题

在使用系统分享的时候会弹出系统分享的列表,然后点击instagram才进入instagram的分享页,和需求不符

3. 方案:最后找到解决方案:

通过openURL进入instagram的分享页(此url在官方API中没有)

使用 openURL 打开"instagram://library?AssetPath=assets-library" 可以跳转到instagram的分享页面(取相册中第一张图片)

注:这里需要用户同意相册权限

if let instagramURL = URL(string: "instagram://library?AssetPath=assets-library"), UIApplication.shared.canOpenURL(instagramURL) {
            if #available(iOS 10.0, *) {
                UIApplication.shared.open(instagramURL, options: [:], completionHandler: { (_) in })
            } else {
                UIApplication.shared.openURL(instagramURL)
            }
        } else {
            // 提示没有instagram
        }
上一篇 下一篇

猜你喜欢

热点阅读