大佬教程收集整理的这篇文章主要介绍了iOS – 将图像发送到Instagram – DocumentInteraction,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
请注意,我知道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最终@L_607_10@/@L_607_10@扩展:“Instagram最近为其iOS应用程序@L_607_10@了共享扩展功能.现在,您可以直接将第三方应用程序的照片分享到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:co@R_616_10443@Tinfo:)),nil) } func image(image: UIImage,didFinishSavingWithError error: NSError?,co@R_616_10443@Tinfo: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所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。