iOS – 将图像发送到Instagram – DocumentInteraction

iOS – 将图像发送到Instagram – DocumentInteraction,第1张

概述是否可以绕过行动共享表将照片分享给Instagram? 请注意,我知道UIDocumentInteractionController和钩子,事实上它工作正常.使用他们的示例代码,您可以获得Copy to Instagram选项(如果您使用独家UTI或可以处理JPG / PNG的大型应用程序列表,以及Instagram,则可以是唯一的). 这很好,但我想知道是否有办法执行“复制到Instagram” 是否可以绕过行动共享表将照片分享给Instagram?

请注意,我知道UIdocumentInteractionController和钩子,事实上它工作正常.使用他们的示例代码,您可以获得copy to Instagram选项(如果您使用独家UTI或可以处理JPG / PNG的大型应用程序列表,以及Instagram,则可以是唯一的).

这很好,但我想知道是否有办法执行“复制到Instagram” *** 作,而无需在iOS 9中显示UIdocumentInteractionController菜单.

为了记录,这是完美运行的代码的简化版本.假设你有一个有效的NSURL ……

guard let data: NSData = NSData(contentsOfURL: url),image = UIImage(data: data) else {            return        }        let imageData = UIImageJPEGRepresentation(image,100)        let captionString = "caption"        let writePath = (NstemporaryDirectory() as Nsstring).stringByAppendingPathComponent("instagram.ig")        guard let _ = imageData?.writetofile(writePath,atomically: true) else {            return        }        let fileURL = NSURL(fileURLWithPath: writePath)        self.documentController = UIdocumentInteractionController(URL: fileURL)        self.documentController.delegate = self        self.documentController.UTI = "com.instagram.photo"        self.documentController.annotation = NSDictionary(object: captionString,forKey: "InstagramCaption")        self.documentController.presentopenInMenuFromrect(vIEwController.vIEw.frame,inVIEw: vIEwController.vIEw,animated: true)

问题是,这将提供一个“ *** 作表”,我想避免这样做,如果可能的话,我想使用instagram.ige(或任何名称使其独占)并跳过此ActionSheet.

那可能吗?

更新:我还没有找到解决方案,但似乎Instagram最终添加/添加扩展:“Instagram最近为其iOS应用程序添加了共享扩展功能.现在,您可以直接将第三方应用程序的照片分享到Instagram”
来源:http://www.macworld.com/article/3080038/data-center-cloud/new-instagram-feature-for-ios-makes-it-easier-to-share-photos-from-other-apps.html

解决方法
import Photos...func postimageToInstagram(image: UIImage) {        UIImageWritetoSavedPhotosAlbum(image,self,#selector(SocialShare.image(_:dIDFinishSavingWithError:contextInfo:)),nil)}func image(image: UIImage,dIDFinishSavingWithError error: NSError?,contextInfo:UnsafePointer<VoID>) {        if error != nil {            print(error)        }        let fetchOptions = PHFetchOptions()        fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate",ascending: false)]        let fetchResult = PHAsset.fetchAssetsWithMediaType(.Image,options: fetchOptions)        if let lastAsset = fetchResult.firstObject as? PHAsset {            let localIDentifIEr = lastAsset.localIDentifIEr            let u = "instagram://library?LocalIDentifIEr=" + localIDentifIEr            let url = NSURL(string: u)!            if UIApplication.sharedApplication().canopenURL(url) {                UIApplication.sharedApplication().openURL(NSURL(string: u)!)            } else {                let alertController = UIAlertController(Title: "Error",message: "Instagram is not installed",preferredStyle: .Alert)                alertController.addAction(UIAlertAction(Title: "OK",style: .Default,handler: nil))                self.presentVIEwController(alertController,animated: true,completion: nil)            }        }}
总结

以上是内存溢出为你收集整理的iOS – 将图像发送到Instagram – DocumentInteraction全部内容,希望文章能够帮你解决iOS – 将图像发送到Instagram – DocumentInteraction所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1099333.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存