iOS9 系统分享调用(UIActivityViewController)
猴子原创,欢迎转载。转载请注明: 转载自Cocos2Der-CSDN,谢谢!
原文地址: http://blog.csdn.net/cocos2der/article/details/49615109
昨天有网友说我写的那段系统分享代码在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)的更多相关文章
- iOS9系统分享失败问题解决
因为iOS9系统需要设置打开QQ和微信的白名单,如果出现无法分享或者直接提示分享失败,试一下在infoPlist中添加以下白名单 http://wiki.mob.com/ios9-对sharesdk的 ...
- 仿简书分享:UIActivityViewController系统原生分享
接下来介绍UIActivityViewController: 1. 创建要分享的数据内容,加在一个数组 ActivityItems里. NSString *textToShare = @"我 ...
- android - 调用系统分享功能分享图片
step1: 编写分享代码, 将Uri的生成方式改为由FileProvider提供的临时授权路径,并且在intent中添加flag 注意:在Android7.0之后,调用系统分享,传入URI的时候可能 ...
- Android 调用系统分享文字、图片、文件,可直达微信、朋友圈、QQ、QQ空间、微博
原文:Android 调用系统分享文字.图片.文件,可直达微信.朋友圈.QQ.QQ空间.微博 兼容SDK 18以上的系统,直接调用系统分享功能,分享文本.图片.文件到第三方APP,如:微信.QQ.微博 ...
- Android调用系统分享功能总结
Android分享-调用系统自带的分享功能 实现分享功能的几个办法 1.调用系统的分享功能 2.通过第三方SDK,如ShareSDK,友盟等 3.自行使用各自平台的SDK,比如QQ,微信,微博各自的S ...
- iOS 6分享列表——UIActivityViewController详解
iOS 6分享列表——UIActivityViewController详解 2013-06-03 01:42:33 发表评论 在iOS 6之后提供了一个分享列表视图,它通过UIActivity ...
- uniapp分享功能-系统分享
uni-app分享 uniapp官网地址:https://uniapp.dcloud.io/api/plugins/share?id=sharewithsystem 调用系统分享组件发送分享消息,不需 ...
- paintEvent(QPaintEvent*)是系统自动调用的
qt中函数paintEvent(QPaintEvent*)是被系统自动调用. paintEvent(QPaintEvent *)函数是QWidget类中的虚函数,用于ui的绘制,会在多种情况下被其他函 ...
- Android应用中实现系统“分享”接口
在android下各种文件管理器中,我们选择一个文件,点击分享可以看到弹出一些app供我们选择,这个是android系统分享功能,我们做的app也可以出现在这个列表中. 第一步:在Manifest.x ...
随机推荐
- 使用github搭建网站
http://blog.csdn.net/pipisorry/article/details/51707366 使用github建站 github设计了Pages功能,允许用户自定义项目首页,用来替代 ...
- Calling LoadLibraryEx on ISAPI filter failed
今天在访问IIS下的站点时莫名奇妙的遇到这个问题Calling LoadLibraryEx on ISAPI filter"C://..." failed,前面引号中的" ...
- python访问redis
python访问redis 1 Linux上安装redis a) 下载 $ wget http://download.redis.io/releases/redis-3.0.5.tar.gz b) 编 ...
- Dynamics CRM CRM Explorer missing from Visual Studio 2012
CRMSDK中提供的develop toolkit工具比较适合初级开发者或者是多人团队的开发,在代码版本控制及部署上均有明显的优势. 但今天在装完这个工具后,打开vs2012可以新建一个package ...
- 关于android app签名文件获取sha1和MD值
最近在做百度地图的嵌入,因为从同事接手的android app,所以第一次接触android的签名. 总的来说签名还比较简单,我用的是eclipse ADT自带的签名工具来做的签名,方法如下: 选择项 ...
- 利用openssl管理证书及SSL编程第2部分:在Windows上编译 openssl
利用openssl管理证书及SSL编程第2部分:在Windows上编译 openssl 首先mingw的环境搭建,务必遵循下文: http://blog.csdn.net/ubuntu64fan/ar ...
- 用过的一些Android设备调试特性注意点(挖坑帖)
华为3C Activity切换动画偏快. 显示大图时不容易出现OOM(应用最大内容要比其他手机大一点),所以调试OOM问题时不要用此手机,否则难以发现问题. 小米3 不要调用系统的裁图功能.因为返回的 ...
- Android实现自定义的相机
使用系统相机 android中使用系统相机是很方便的,单这仅仅是简单的使用而已,并不能获得什么特殊的效果. 要想让应用有相机的action,咱们就必须在清单文件中做一些声明,好让系统知道,如下 < ...
- 2015 Objective-C 三大新特性
Overview 自 WWDC 2015 推出和开源 Swift 2.0 后,大家对 Swift 的热情又一次高涨起来,在羡慕创业公司的朋友们大谈 Swift 新特性的同时,也有很多像我一样工作上依然 ...
- linux杀死进程的简单讲解
一. 终止进程的工具kill .killall.pkill.xkill 终止一个进程或终止一个正在运行的程序,一般是通过kill .killall.pkill.xkill 等进行.比如一个程序已经死掉 ...