iOS9 系統(tǒng)分享調(diào)用之UIActivityViewController
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ù)姆椒?。在iPad上,必須通過(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)單好用。

下面是我修改之后的代碼:
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)
}
}
}
- iOS開(kāi)發(fā)中ViewController的頁(yè)面跳轉(zhuǎn)和彈出模態(tài)
- iOS開(kāi)發(fā)中WebView的基本使用方法簡(jiǎn)介
- iOS開(kāi)發(fā)中使用UIScrollView實(shí)現(xiàn)圖片輪播和點(diǎn)擊加載
- iOS開(kāi)發(fā)中的ViewController轉(zhuǎn)場(chǎng)切換效果實(shí)現(xiàn)簡(jiǎn)介
- IOS中UIWebView加載Loading的實(shí)現(xiàn)方法
- IOS中使用UIWebView 加載網(wǎng)頁(yè)、文件、 html的方法
- ionic在開(kāi)發(fā)ios系統(tǒng)微信時(shí)鍵盤(pán)擋住輸入框的解決方法(鍵盤(pán)彈出問(wèn)題)
- 解決ios模擬器不能彈出鍵盤(pán)問(wèn)題的方法
- android底部彈出iOS7風(fēng)格對(duì)話(huà)選項(xiàng)框(QQ對(duì)話(huà)框)--第三方開(kāi)源之IOS_Dialog_Library
- iOS仿簡(jiǎn)書(shū)、淘寶等App的View彈出效果
相關(guān)文章
iOS App開(kāi)發(fā)中UITextField組件的常用屬性小結(jié)
這篇文章主要介紹了iOS App開(kāi)發(fā)中UITextField組件的常用屬性小結(jié),文中還介紹了UITextField隱藏鍵盤(pán)及為內(nèi)容增加校驗(yàn)的兩個(gè)使用技巧,需要的朋友可以參考下2016-04-04
解決iOS11圖片下拉放大出現(xiàn)信號(hào)欄白條的bug問(wèn)題
這篇文章主要介紹了iOS11圖片下拉放大出現(xiàn)信號(hào)欄白條的bug問(wèn)題,需要的朋友參考下吧2017-09-09
iOS指紋驗(yàn)證TouchID應(yīng)用學(xué)習(xí)教程2
這篇文章主要為大家詳細(xì)iOS指紋驗(yàn)證TouchID應(yīng)用學(xué)習(xí)教程的第一篇,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-01-01
iOS中UIActivityIndicatorView的用法及齒輪等待動(dòng)畫(huà)實(shí)例
UIActivityIndicatorView活動(dòng)指示器最常見(jiàn)的用法便是用來(lái)制作那個(gè)程序中的齒輪轉(zhuǎn)動(dòng)的等待效果,接下來(lái)我們回來(lái)簡(jiǎn)單整理iOS中UIActivityIndicatorView的用法及齒輪等待動(dòng)畫(huà)實(shí)例:2016-05-05
LRecyclerView側(cè)滑iOS阻塞效果不完整的解決辦法
這篇文章主要介紹了LRecyclerView側(cè)滑iOS阻塞效果不完整的解決辦法,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友參考下2016-12-12
iOS 原生實(shí)現(xiàn)掃描二維碼和條形碼功能限制掃描區(qū)域
這篇文章主要介紹了iOS 原生實(shí)現(xiàn)掃描二維碼和條形碼功能限制掃描區(qū)域,需要的朋友可以參考下2017-03-03

