UIActivityViewController類是一個尺度的view controller,通個應用這個controller,你的運用法式便可以供給各類辦事。
體系供給了一些通用的尺度辦事,例如拷貝內容至粘貼板、宣布一個通知布告至社交網、經由過程email或許SMS發送內容。
運用法式異樣可以自界說辦事。(我的微信分享就屬於自界說辦事, 以後將會寫一篇教程引見)
你的運用法式擔任設置裝備擺設、展示息爭雇這個view controller。
viewcontroller的設置裝備擺設觸及到viewcontroller須要用到的詳細的數據對象。(也能夠指定自界說辦事列表,讓運用法式支撐這些辦事)。
在展示view controller時,必需依據以後的裝備類型,應用恰當的辦法。在iPad上,必需經由過程popover來展示view controller。在iPhone和iPodtouch上,必需以模態的方法展示。
昨天有網友說我寫的那段體系分享代碼在IOS9上有warning,看下了本來IOS8以後UIPopoverController被放棄了。新增長的UIPopoverPresentationController在掌握PopView上更簡略好用。

上面是我修正以後的代碼:
1. 在app內以子視圖方法翻開其他app預覽,僅支撐6.0以上
openAppWithIdentifier(appId: String)
2. 分享文字圖片信息,ipad上會以sourceView為核心彈出選擇視圖
share(textToShare: String, url: String, image: UIImage, sourceView: UIView)
/// 在app內以子視圖方法翻開其他app預覽,僅支撐6.0以上
private func openAppWithIdentifier(appId: String) {
if let _ = NSClassFromString("SKStoreProductViewController") {
let storeProductViewController = SKStoreProductViewController()
storeProductViewController.delegate = self
let dict = NSDictionary(object:appId, forKey:SKStoreProductParameterITunesItemIdentifier) as! [String : AnyObject]
storeProductViewController.loadProductWithParameters(dict, completionBlock: { (result, error) -> Void in
// self.presentViewController(storeProductViewController, animated: true, completion: nil)
})
self.presentViewController(storeProductViewController, animated: true, completion: nil)
}else {
UIApplication.sharedApplication().openURL(NSURL(string: "itms-apps://itunes.apple.com/app/id\(appId)")!)
}
}
/// 分享文字圖片信息,ipad上會以sourceView為核心彈出選擇視圖
private func share(textToShare: String, url: String, image: UIImage, sourceView: UIView) {
let objectsToShare = [textToShare, url, image]
let activityViewController = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
if UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Phone {
self.presentViewController(activityViewController, animated: true, completion: nil)
}else {
let popover = activityViewController.popoverPresentationController
if (popover != nil){
popover?.sourceView = sourceView
popover?.sourceRect = sourceView.frame
popover?.permittedArrowDirections = UIPopoverArrowDirection.Any
self.presentViewController(activityViewController, animated: true, completion: nil)
}
}
}
【iOS9 體系分享挪用之UIActivityViewController】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!