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
現支持的領域數組
使用Siri步驟參考: http://www.jianshu.com/p/0881bb0ff538 http://www.tuicool.com/articles/mAnAnmR https://developer.apple.com/videos/play/wwdc2016/217/網絡
#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; }
[center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) { NSLog(@"%@",settings); }];
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
目前能夠攜帶圖片,音頻,視頻,但附件大小有限制: (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];
//每一個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.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
官方提供的擴展類型
無需代碼,添加Sticker Pack Application 素材拖入Sticker Pack文件夾 便可
代碼中添加貼圖
#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]; }
最重要的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