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

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

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

2020-07-26 03:32:45
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

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

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

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

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

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

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

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

這里寫(xiě)圖片描述

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

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

openAppWithIdentifier(appId: String)

2. 分享文字圖片信息,ipad上會(huì)以sourceView為焦點(diǎn)彈出選擇視圖

share(textToShare: String, url: String, image: UIImage, sourceView: UIView)/// 在app內(nèi)以子視圖方式打開(kā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上會(huì)以sourceView為焦點(diǎn)彈出選擇視圖 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)  } } }

發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 修水县| 酒泉市| 新巴尔虎左旗| 西丰县| 吐鲁番市| 清涧县| 峨眉山市| 汶川县| 宁安市| 三亚市| 潮安县| 民勤县| 深州市| 浦县| 萝北县| 交城县| 祁门县| 津南区| 论坛| 温宿县| 尼玛县| 博乐市| 贺州市| 芜湖县| 隆回县| 色达县| 开鲁县| 武邑县| 阿图什市| 绥滨县| 呼和浩特市| 尉氏县| 寻乌县| 康保县| 莎车县| 上饶县| 瓦房店市| 清徐县| 石泉县| 门头沟区| 五寨县|