iOS9 系統(tǒng)分享調用之UIActivityViewController
UIActivityViewController類是一個標準的view controller,通個使用這個controller,你的應用程序就可以提供各種服務。
系統(tǒng)提供了一些通用的標準服務,例如拷貝內容至粘貼板、發(fā)布一個公告至社交網(wǎng)、通過email或者SMS發(fā)送內容。
應用程序同樣可以自定義服務。(我的微信分享就屬于自定義服務, 之后將會寫一篇教程介紹)
你的應用程序負責配置、展現(xiàn)和解雇這個view controller。
viewcontroller的配置涉及到viewcontroller需要用到的具體的數(shù)據(jù)對象。(也可以指定自定義服務列表,讓應用程序支持這些服務)。
在展現(xiàn)view controller時,必須根據(jù)當前的設備類型,使用適當?shù)姆椒āT趇Pad上,必須通過popover來展現(xiàn)view controller。在iPhone和iPodtouch上,必須以模態(tài)的方式展現(xiàn)。
昨天有網(wǎng)友說我寫的那段系統(tǒng)分享代碼在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)
}
}
}
- iOS開發(fā)中ViewController的頁面跳轉和彈出模態(tài)
- iOS開發(fā)中WebView的基本使用方法簡介
- iOS開發(fā)中使用UIScrollView實現(xiàn)圖片輪播和點擊加載
- iOS開發(fā)中的ViewController轉場切換效果實現(xiàn)簡介
- IOS中UIWebView加載Loading的實現(xiàn)方法
- IOS中使用UIWebView 加載網(wǎng)頁、文件、 html的方法
- ionic在開發(fā)ios系統(tǒng)微信時鍵盤擋住輸入框的解決方法(鍵盤彈出問題)
- 解決ios模擬器不能彈出鍵盤問題的方法
- android底部彈出iOS7風格對話選項框(QQ對話框)--第三方開源之IOS_Dialog_Library
- iOS仿簡書、淘寶等App的View彈出效果
相關文章
iOS App開發(fā)中UITextField組件的常用屬性小結
這篇文章主要介紹了iOS App開發(fā)中UITextField組件的常用屬性小結,文中還介紹了UITextField隱藏鍵盤及為內容增加校驗的兩個使用技巧,需要的朋友可以參考下2016-04-04
解決iOS11圖片下拉放大出現(xiàn)信號欄白條的bug問題
這篇文章主要介紹了iOS11圖片下拉放大出現(xiàn)信號欄白條的bug問題,需要的朋友參考下吧2017-09-09
iOS中UIActivityIndicatorView的用法及齒輪等待動畫實例
UIActivityIndicatorView活動指示器最常見的用法便是用來制作那個程序中的齒輪轉動的等待效果,接下來我們回來簡單整理iOS中UIActivityIndicatorView的用法及齒輪等待動畫實例:2016-05-05
LRecyclerView側滑iOS阻塞效果不完整的解決辦法
這篇文章主要介紹了LRecyclerView側滑iOS阻塞效果不完整的解決辦法,非常不錯,具有參考借鑒價值,需要的朋友參考下2016-12-12
iOS 原生實現(xiàn)掃描二維碼和條形碼功能限制掃描區(qū)域
這篇文章主要介紹了iOS 原生實現(xiàn)掃描二維碼和條形碼功能限制掃描區(qū)域,需要的朋友可以參考下2017-03-03

