iOS8新特性扩展(Extension)应用之二——分享插件
来源:互联网 发布:用网络看电视直播 编辑:程序博客网 时间:2024/04/30 10:59
iOS8新特性扩展(Extension)应用之二——分享插件
在上一篇博客中,介绍了iOS8新特性扩展功能之一的Today功能:http://my.oschina.net/u/2340880/blog/485533,这里我们再介绍一下分享的扩展功能。
在iOS8之前,除了一些主流的社交平台,例如苹果支持内容分享外,其他开发者的应用若要加入分享的功能,将会十分的复杂。在iOS8的新特性中,apple为我们准备了这样的扩展功能。
首先创建工程,在我们的工程中新建一个Target:
之后,模板中会为我们创建一个controller类,这个controller用于控制我们的分享插件,里面内容:
@implementation ShareViewController//这个函数用于判断分享内容的可用性,我们在其中获取分享的内容进行检查- (BOOL)isContentValid { // Do validation of contentText and/or NSExtensionContext attachments here return YES;}//点击post按钮后出发的方法,我们可以在这里将分享的内容进行上传等操作- (void)didSelectPost { // This is called after the user selects Post. Do the upload of contentText and/or NSExtensionContext attachments. // Inform the host that we're done, so it un-blocks its UI. Note: Alternatively you could call super's -didSelectPost, which will similarly complete the extension context. [self.extensionContext completeRequestReturningItems:@[] completionHandler:nil];}//这里用于设置分享插件的附件按钮- (NSArray *)configurationItems { // To add configuration options via table cells at the bottom of the sheet, return an array of SLComposeSheetConfigurationItem here. return @[];}@end
除此之外,还有一些常用的属性:
- (void)presentationAnimationDidFinish;
弹出视图动画结束后执行的方法
@property (readonly, NS_NONATOMIC_IOSONLY) NSString *contentText;
分享的内容文字
@property (copy, NS_NONATOMIC_IOSONLY) NSString *placeholder;
默认显示的提示文字
- (void)didSelectCancel;
取消按钮执行的方法
我们在代码中如下添加后运行:
@implementation ShareViewController-(NSString *)placeholder{ return @"提示文字";}- (NSArray *)configurationItems { // To add configuration options via table cells at the bottom of the sheet, return an array of SLComposeSheetConfigurationItem here. SLComposeSheetConfigurationItem * item =[[SLComposeSheetConfigurationItem alloc]init]; item.title=@"地点"; item.value=@"城门"; return @[item];}
我们用系统的相册做测试,点击相片的分享按钮:
点击MORE,添加我们的扩展插件。
这时分享栏中多了一个我们的插件,点击效果如下:
还有一点我们需要了解,在这个扩展的plist文件中,有这样一个键:NSExtensionAttributes,里面有一个NSExtensionActivationRule的字典,其中可以设置一些键值,对分享插件的属性进行控制。
这些键的写法在官方文档中的介绍如下:
这些键的意义,文档中介绍的很清楚,我们可以根据需要进行设置。
- iOS8新特性扩展(Extension)应用之二——分享插件
- iOS8新特性扩展(Extension)应用之三——照片编辑插件
- iOS8新特性扩展(Extension)应用之四——自定义键盘控件
- iOS8 study for ——iOS8新特性之扩展(Extension)
- iOS8新特性扩展(Extension)应用之一——Today扩展
- iOS8新特性Extension之Today插件的代码测试
- iOS 8新特性之扩展(Extension)
- iOS ios8新特性之扩展
- iOS ios8新特性之扩展详解
- iOS ios8新特性之扩展
- iOS8 SDK新特性之扩展详解
- ios8 share extension 分享扩展 问题小结
- iOS8新特性测试入门-----Share Extension
- iOS8扩展插件Extension的开发
- IOS8新特性NSExtensionMainStoryboard (扩展)
- iOS8之后创建Action Extension应用扩展
- iOS新特性之扩展开发攻略 - Share Extension
- iOS新特性之扩展开发攻略 - Share Extension
- AutoLayout代码控制约束是否起作用
- JavaScript基础——引用类型(二)日期类型Date、正则表达式类型RegExp
- OpenGLES---模型/观察/投影矩阵
- 如何转成libsvm支持的数据格式并做回归分析
- Android N Preview Notification API (通知)
- iOS8新特性扩展(Extension)应用之二——分享插件
- HDU 2660 Accepted Necklace(DFS解01背包)
- Ext.data.HttpProxy传参的中文乱码解决办法
- 【深入浅出Node.js系列十二】Nodejs日志管理log4js
- android 游戏 实战打飞机游戏 菜单页面(1)
- 一道关于信号的题
- httpModules 与 httpHandlers
- 深入理解计算机系统--->并发与并行
- Retrofit初体验,复杂数据gson解析