<pre>前言:iOS 10 發(fā)布有一段時(shí)間了,本次主要看看iOS 10 有哪些新的特性</pre>
- Widget 可以在搜索界面、主屏可以看到
- Message 可以添加自定義內(nèi)容(類型微信表情),Message中添加自定義程序內(nèi)容
- SiriSDK開(kāi)放 可以通過(guò)語(yǔ)音調(diào)取有特定功能的App內(nèi)容
- Notifications添加新的樣式,可以實(shí)現(xiàn)預(yù)覽
1.Today Widget 變更
主要是添加顯示模式:
<pre>
<code>
@property (nonatomic, assign) NCWidgetDisplayMode widgetLargestAvailableDisplayMode NS_AVAILABLE_IOS(10_0);</code>
<code>
@property (nonatomic, assign, readonly) NCWidgetDisplayMode widgetActiveDisplayMode NS_AVAILABLE_IOS(10_0);</code>
</pre>
<pre>
NCWidgetDisplayModeCompact:固定高度
NCWidgetDisplayModeExpanded:動(dòng)態(tài)高度
</pre>
通過(guò)以下代碼可以設(shè)置展開(kāi)還是顯示
<pre><code>self.extensionContext.widgetLargestAvailableDisplayMode = NCWidgetDisplayModeExpanded;</code></pre>
2.Message 變更 (主要說(shuō)明Message + App模式)
通過(guò)繼承<code>MSMessagesAppViewController</code>,即可實(shí)現(xiàn)App
重點(diǎn)需要關(guān)注以下方法:
<pre>
<code>
//添加Message對(duì)象
- (void)insertMessage:(MSMessage *)message completionHandler:(nullable void (^)(NSError * _Nullable))completionHandler;
_
//添加Sticker對(duì)象 - (void)insertSticker:(MSSticker *)sticker completionHandler:(nullable void (^)(NSError * _Nullable))completionHandler;
_
//添加文本信息 - (void)insertText:(NSString *)text completionHandler:(nullable void (^)(NSError * _Nullable))completionHandler;
_
//添加附件 - (void)insertAttachment:(NSURL *)URL withAlternateFilename:(nullable NSString *)filename completionHandler:(nullable void (^)(NSError * _Nullable))completionHandler;
</code>
</pre>
構(gòu)建消息體
- (MSMessage *)buildMessageWithItem:(Item *)item atIndexPath:(NSIndexPath *)indexPath{
if (!self.activeConversation){
return nil;
}
MSSession *session = [[MSSession alloc]init];
if (self.activeConversation.selectedMessage.session){
session = self.activeConversation.selectedMessage.session;
}
MSMessageTemplateLayout *layout = [[MSMessageTemplateLayout alloc]init];
layout.caption = [NSString stringWithFormat:@"%@",item.caption];
layout.subcaption = [NSString stringWithFormat:@"%@",item.subcaption];
layout.image = item.image;
MSMessage *message = [[MSMessage alloc]initWithSession:session];
message.URL = [NSURL URLWithString:item.url];
message.layout = layout;
return message;
}
說(shuō)明:<code>MSMessageTemplateLayout</code>為Message消息體的布局模板
SiriSDK(待更新)
Notifications可以在通知中顯示圖片
主要是<code>UNNotificationServiceExtension</code>和<code>UNMutableNotificationContent</code>的配合使用
通過(guò)<code>UNNotificationServiceExtension</code>下載相應(yīng)的圖片
再通過(guò)<code>UNMutableNotificationContent</code>展示對(duì)應(yīng)的圖片