国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > iOS > 正文

iOS9 系統(tǒng)分享調(diào)用之UIActivityViewController

2019-10-21 18:57:03
字體:
供稿:網(wǎng)友
UIActivityViewController類是一個標(biāo)準(zhǔn)的view controller,通個使用這個controller,你的應(yīng)用程序就可以提供各種服務(wù)。本文給大家介紹iOS9 系統(tǒng)分享調(diào)用之UIActivityViewController,感興趣的朋友一起學(xué)習(xí)吧
 

UIActivityViewController類是一個標(biāo)準(zhǔn)的view controller,通個使用這個controller,你的應(yīng)用程序就可以提供各種服務(wù)。

系統(tǒng)提供了一些通用的標(biāo)準(zhǔn)服務(wù),例如拷貝內(nèi)容至粘貼板、發(fā)布一個公告至社交網(wǎng)、通過email或者SMS發(fā)送內(nèi)容。

應(yīng)用程序同樣可以自定義服務(wù)。(我的微信分享就屬于自定義服務(wù), 之后將會寫一篇教程介紹)

你的應(yīng)用程序負責(zé)配置、展現(xiàn)和解雇這個view controller。

viewcontroller的配置涉及到viewcontroller需要用到的具體的數(shù)據(jù)對象。(也可以指定自定義服務(wù)列表,讓應(yīng)用程序支持這些服務(wù))。

在展現(xiàn)view controller時,必須根據(jù)當(dāng)前的設(shè)備類型,使用適當(dāng)?shù)姆椒āT趇Pad上,必須通過popover來展現(xiàn)view controller。在iPhone和iPodtouch上,必須以模態(tài)的方式展現(xiàn)。

昨天有網(wǎng)友說我寫的那段系統(tǒng)分享代碼在iOS9上有warning,看下了原來ios8之后UIPopoverController被廢棄了。新增加的UIPopoverPresentationController在控制PopView上更簡單好用。

iOS9 系統(tǒng)分享調(diào)用之UIActivityViewController

下面是我修改之后的代碼:

1. 在app內(nèi)以子視圖方式打開其他app預(yù)覽,僅支持6.0以上

openAppWithIdentifier(appId: String)

2. 分享文字圖片信息,ipad上會以sourceView為焦點彈出選擇視圖

share(textToShare: String, url: String, image: UIImage, sourceView: UIView)/// 在app內(nèi)以子視圖方式打開其他app預(yù)覽,僅支持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)  } } }
 


注:相關(guān)教程知識閱讀請移步到IOS開發(fā)頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 清涧县| 嘉鱼县| 玛曲县| 河北省| 托克逊县| 喜德县| 青铜峡市| 雷州市| 边坝县| 开原市| 文安县| 贵德县| 那坡县| 富裕县| 镇远县| 泰州市| 务川| 都安| 定远县| 鄂伦春自治旗| 资源县| 阿克| 乌拉特中旗| 碌曲县| 太和县| 固原市| 安徽省| 类乌齐县| 靖西县| 城步| 安泽县| 开平市| 桃江县| 安泽县| 金川县| 夏河县| 纳雍县| 隆昌县| 微山县| 乐亭县| 政和县|