美文网首页iOS开发
IOS 10 新特性以及介绍

IOS 10 新特性以及介绍

作者: i_belive | 来源:发表于2016-08-30 18:51 被阅读72次

    <pre>前言:iOS 10 发布有一段时间了,本次主要看看iOS 10 有哪些新的特性</pre>

    • Widget 可以在搜索界面、主屏可以看到
    • Message 可以添加自定义内容(类型微信表情),Message中添加自定义程序内容
    • SiriSDK开放 可以通过语音调取有特定功能的App内容
    • Notifications添加新的样式,可以实现预览

    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:动态高度
    </pre>
    通过以下代码可以设置展开还是显示
    <pre><code>self.extensionContext.widgetLargestAvailableDisplayMode = NCWidgetDisplayModeExpanded;</code></pre>

    2.Message 变更 (主要说明Message + App模式)

    通过继承<code>MSMessagesAppViewController</code>,即可实现App
    重点需要关注以下方法:
    <pre>
    <code>
    //添加Message对象

    • (void)insertMessage:(MSMessage *)message completionHandler:(nullable void (^)(NSError * _Nullable))completionHandler;
      _
      //添加Sticker对象
    • (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>

    构建消息体

    - (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;
    }
    

    说明:<code>MSMessageTemplateLayout</code>为Message消息体的布局模板

    SiriSDK(待更新)

    Notifications可以在通知中显示图片
    主要是<code>UNNotificationServiceExtension</code>和<code>UNMutableNotificationContent</code>的配合使用
    通过<code>UNNotificationServiceExtension</code>下载相应的图片
    再通过<code>UNMutableNotificationContent</code>展示对应的图片

    未完待续

    相关文章

      网友评论

        本文标题:IOS 10 新特性以及介绍

        本文链接:https://www.haomeiwen.com/subject/qdofettx.html