十四.iOS10新特性

14.1 Siri扩展

SiriKit的两个框架 1.Intents框架用于支持应用和系统之间的基础通讯 2.Intents UI框架提供了展现自定义用户接口的能力 Intents列表: https://developer.apple.com/library/content/documentation/Intents/Conceptual/SiriIntegrationGuide/SiriDomains.html#//apple_ref/doc/uid/TP40016875-CH9-SW2html

SiriKit:ios

输入图片说明

应用开发者只需关注: 词汇(语音,意图), 应用逻辑(意图,动做,响应),用户界面(响应)swift

现支持的领域数组

  • 语音和视频通话
  • 发送消息
  • 收付款
  • 照片
  • 出行预约
  • 健身
  • 汽车控制命令(限汽车供应商)
  • CarPay(限汽车供应商)
  • 餐厅预约(须要苹果额外支持)

使用Siri步骤参考: http://www.jianshu.com/p/0881bb0ff538 http://www.tuicool.com/articles/mAnAnmR https://developer.apple.com/videos/play/wwdc2016/217/网络

14.2 改进的通知

14.2.1申请权限:

#import <UserNotifications/UserNotifications.h>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
  center.delegate = self;
    [center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge |     
    UNAuthorizationOptionSound | 
    UNAuthorizationOptionAlert) 
    completionHandler:^(BOOL granted, NSError * _Nullable error) {
        if (!error) {
            NSLog(@"request authorization succeeded!");
        }
    }];
    
       return YES;
}

14.2.2获取用户详细设定

[center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
        NSLog(@"%@",settings);
}];

14.2.3触发器

  • Push:支持远程推送
  • 时间间隔:定时触发,支持屡次重复触发 UNTimeIntervalNotificationTrigger
  • 日历:在某个时间点进行触发 UNCalendarNotificationTrigger
  • 定位服务:当用户进入或离开某一区域时触发 UNLocationNotificationTrigger
NSString *categoryIndetifier = @"HelloNotificationD";
	UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc]init];
	content.title = @"IOS10 Push";
	content.subtitle = @"trigger by time Interval";
	content.body = @"Hello Push";
	content.categoryIdentifier = categoryIndetifier;
	
	UNTimeIntervalNotificationTrigger *timeInterval = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:61 repeats:YES];
	UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:@"request" content:content trigger:timeInterval];
	[center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
		NSLog(@"Push Over");
	}];

时间间隔重复发送,间隔必须大于60S,要否则会崩溃app

14.2.4携带附件

目前能够携带图片,音频,视频,但附件大小有限制: (1)图片,包括JPEG,GIF,PNG,最大为10M (2)音频,包括AIFF,MP3,WAV,MPEG4音频,最大为5M (3)视频,包括MPEG,MPEG2,MPEG4,AVI,最大为30M框架

添加本地附件:ide

NSURL *fileURL = [[NSBundle mainBundle]URLForResource:@"picture" withExtension:@"png"];
	UNNotificationAttachment *attachment = [UNNotificationAttachment attachmentWithIdentifier:@"attachment" 
	URL:fileURL 
	options:nil 
	error:nil];
	content.attachments = @[attachment];

14.2.5为通知添加交互

//每一个action表明一个可用于交互的UI元素,本例是一个按钮,也能够是一个文本UNTextInputNotificationAction
	UNNotificationAction *lookAction = [UNNotificationAction actionWithIdentifier:@"action.join" title:@"接收邀请" options:UNNotificationActionOptionAuthenticationRequired];

	UNNotificationAction *joinAction = [UNNotificationAction actionWithIdentifier:@"action.look" title:@"查看邀请" options:UNNotificationActionOptionForeground];
	
	UNNotificationAction *cancelAction = [UNNotificationAction actionWithIdentifier:@"action.cancel" title:@"取消" options:UNNotificationActionOptionDestructive];
	
	UNTextInputNotificationAction *inputAction = [UNTextInputNotificationAction actionWithIdentifier:@"action.input" title:@"输入" options:UNNotificationActionOptionForeground textInputButtonTitle:@"发送" textInputPlaceholder:@"tell me loudly"];
	//category的标识符,应与通知内容的标识符一直
	//每一个category能够包含一组action,以对应某一种通知的多个UI元素
	
	 UNNotificationCategory *notificationCategory = [UNNotificationCategory categoryWithIdentifier:categoryIndetifier actions:@[lookAction, joinAction, cancelAction] intentIdentifiers:@[] options:UNNotificationCategoryOptionCustomDismissAction];
	//将category注册到UNUserNotificationCenter
	  [center setNotificationCategories:[NSSet setWithArray:@[notificationCategory]]];

长按推送显示交互按钮布局

14.2.6自定义展现通知

目前只能用于信息的展现 ###14.2.7远程推送扩展 若是是本地的就简单了只须要在Service Extension的NotificationService.m的ui

-(void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * Nonnull))contentHandler

拿到资源添加到Notification Content,在Notification Content的控制器取到资源本身来作需求处理和展现.

- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {


    self.contentHandler = contentHandler;
    self.bestAttemptContent = [request.content mutableCopy];

    // 资源路径
    NSURL *videoURL = [[NSBundle mainBundle] URLForResource:@"video" withExtension:@"mp4"];
    // 建立附件资源
    // * identifier 资源标识符
    // * URL 资源路径
    // * options 资源可选操做 好比隐藏缩略图之类的
    // * error 异常处理
    UNNotificationAttachment *attachment = [UNNotificationAttachment attachmentWithIdentifier:@"video.attachment" URL:videoURL options:nil error:nil];
    // 将附件资源添加到 UNMutableNotificationContent 中
    if (attachment) {
        self.bestAttemptContent.attachments = @[attachment];
    }

    self.contentHandler(self.bestAttemptContent);
}

远程推送参考文章: http://www.jianshu.com/p/c58f8322a278 http://www.cnblogs.com/oc-bowen/p/6061286.html

14.3 iMessage扩展(iMessage extension)

官方提供的扩展类型

14.3.1添加静态表情包

无需代码,添加Sticker Pack Application 素材拖入Sticker Pack文件夹 便可

14.3.2建立iMessage应用

代码中添加贴图

#import "MessagesViewController.h"


@interface MessagesViewController ()<MSStickerBrowserViewDataSource>
@property (nonatomic) NSArray<MSSticker*>* stickert;//只能放MSSticker对象的数组
@end

@implementation MessagesViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
	// 初始化本地表情包
	[self loadStickers];
	// 建立本地表情包控制器
	[self createStickerBrowserViewController];
}
- (void)loadStickers{
	NSMutableArray *mArray = [NSMutableArray array];
	NSURL *url = [[NSBundle mainBundle] URLForResource:@"maps" withExtension:@"png"];//直接拖曳获取不到路径须要copy Bundle Resources下面的“+”号,手动将文件添加到你的资源文件中
	MSSticker *sticker = [[MSSticker alloc]initWithContentsOfFileURL:url localizedDescription:@"" error:nil];
	NSURL *url1 = [[NSBundle mainBundle] URLForResource:@"mms" withExtension:@"png"];//直接拖曳获取不到路径须要copy Bundle Resources下面的“+”号,手动将文件添加到你的资源文件中
	MSSticker *sticker1 = [[MSSticker alloc]initWithContentsOfFileURL:url1 localizedDescription:@"" error:nil];
	[mArray addObject:sticker];
	[mArray addObject:sticker1];
	
	self.stickert = mArray;
	
}

// 要想显示图片表情,必需要初始化一个MSStickerBrowserViewController做为根视图
- (void)createStickerBrowserViewController{
	MSStickerBrowserViewController *browserVc = [[MSStickerBrowserViewController alloc]initWithStickerSize:MSStickerSizeSmall];
	[self addChildViewController:browserVc];
	[self.view addSubview:browserVc.view];
	browserVc.stickerBrowserView.backgroundColor = [UIColor orangeColor];
	//设置数据源
	browserVc.stickerBrowserView.dataSource = self;
	browserVc.view.translatesAutoresizingMaskIntoConstraints = NO;
	
	//自动布局
	[self.view.topAnchor constraintEqualToAnchor:browserVc.view.topAnchor].active = YES;
	[self.view.bottomAnchor constraintEqualToAnchor:browserVc.view.bottomAnchor].active = YES;
	[self.view.leftAnchor constraintEqualToAnchor:browserVc.view.leftAnchor].active = YES;
	[self.view.rightAnchor constraintEqualToAnchor:browserVc.view.rightAnchor].active = YES;
}

#pragma mark - MSStickerBrowserViewDataSource 数据源代理方法(必须实现)
// 一共有多少个
-(NSInteger)numberOfStickersInStickerBrowserView:(MSStickerBrowserView *)stickerBrowserView{
	
	return self.stickert.count;
}

// 每个要显示什么
- (MSSticker *)stickerBrowserView:(MSStickerBrowserView *)stickerBrowserView stickerAtIndex:(NSInteger)index{
	
	return self.stickert[index];
}

14.3.3自定义视图可发送图片,音频,视频

最重要的MSConversation 表示一次对话,调用MSConversation 发送消息: 1.会话中插入文本消息

[self.activeConversation insertText:@"文本" completionHandler:^(NSError * _Nullable error) {
		
	}];

2.会话中插入发送贴纸

[self.activeConversation insertSticker:sticker completionHandler:^(NSError * _Nullable error) {  
        if (error) {  
            NSLog(@"%@",error);  
        }  
    }];

3.发送自定义消息

[self.activeConversation insertMessage:message completionHandler:^(NSError * _Nullable error) {
		if (error) {
			NSLog(@"%@",error);
		}
	}];

4.发送附件

[self.activeConversation insertAttachment:url withAlternateFilename:nil completionHandler:^(NSError * _Nullable error) {
		if (error) {
			NSLog(@"%@",error);
		}
	}];

参考连接: http://blog.csdn.net/gzgengzhen/article/details/53115136 https://yq.aliyun.com/articles/60869 ##14.4 VoIP支持(即时通信网络功能开发相关) 网络电话:Voice over Internet Protocol 提供的功能:

  • 通知能力:在通话发起时,接收方能够接受到通知。这个通知是全屏展现且伴有铃声,体验与系统内置的电话服务一致
  • 使第三方语音电话拥有更高优先级,通话时不被系统来电打断
  • 通话记录:通话过程也会记录在系统电话应用的最近通话中
  • 通话拦截:在来电时,对来电进行阻止或识别

CallKit的定位并非提供通讯服务,而是提供系统的入口。第三方应用的开发人员能够调用CallKit的API,将通讯的过程反应到系统的电话应用中,CallKit的核心就是将第三方应用的通讯状态报告给系统

官方: https://developer.apple.com/library/content/samplecode/Speakerbox/Introduction/Intro.html http://devstreaming.apple.com/videos/wwdc/2016/230b83wfxc7m69dm90q/230/230_enhancing_voip_apps_with_callkit.pdf

swift版参考: http://www.jianshu.com/p/2bf4f186dfd9

参考连接: http://dev.qq.com/topic/58009392302e4725036142fc http://www.javashuo.com/article/p-rqmjmhhp-kg.html

其余相关 http://www.jianshu.com/p/f01611160542

第三方CallKit SDK http://www.rongcloud.cn/docs/ios_callkit.html

相关文章
相关标签/搜索