iOS 10多媒體推送

前言

本文只針對(duì)個(gè)推所做的總結(jié),其他推送大同小異

正文

1.添加Notification Service Extension

選擇File->New->Target->Notification Service Extension

image

選擇Activate即可,如果沒有彈出該選項(xiàng)框,需要自行添加相應(yīng)的 scheme。
需要注意的點(diǎn):

  • Extension 的 Bundle Identifier 不能和 Main Target(也就是你自己的 App Target)的 Bundle Identifier 相同,否則會(huì)報(bào) BundeID 重復(fù)的錯(cuò)誤。
  • Extension 的 Bundle Identifier 需要在 Main Target 的命名空間下,比如說 Main Target 的 BundleID 為 ent.getui.xxx,那么Extension的BundleID應(yīng)該類似與ent.getui.xxx.yyy這樣的格式。如果不這么做,會(huì)引起命名錯(cuò)誤。

可以使用.NotificationService的格式

NotificationService的 Deployment Target要設(shè)置最低10.0

2.添加請(qǐng)求代碼

之后項(xiàng)目中會(huì)多出一個(gè)文件夾NotificationService,其中包括一對(duì)關(guān)鍵文件
NotificationService.hNotificationService.m
.m中會(huì)默認(rèn)有兩個(gè)方法

- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
    self.contentHandler = contentHandler;
    self.bestAttemptContent = [request.content mutableCopy];
    
    // Modify the notification content here...
    self.bestAttemptContent.title = [NSString stringWithFormat:@"%@ [modified]", self.bestAttemptContent.title];
    
    self.contentHandler(self.bestAttemptContent);
}
- (void)serviceExtensionTimeWillExpire {
    // Called just before the extension will be terminated by the system.
    // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
    self.contentHandler(self.bestAttemptContent);
}

當(dāng)多媒體消息到達(dá)客戶端后會(huì)走第一個(gè)方法,可以在其中處理資源
但是如果處理時(shí)間過長(zhǎng),將會(huì)進(jìn)入serviceExtensionTimeWillExpire方法進(jìn)行最后的緊急處理。

NotificationService文件夾中的info.plist要添加App Transport Security Settings字典類型,并增加BOOL類型的Allow Arbitrary Loads設(shè)置為YES

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 證書配置+個(gè)推應(yīng)用配置略過 Xcode集成 在項(xiàng)目中添加 Notification Service Extensi...
    看我的大白眼閱讀 2,879評(píng)論 0 4
  • 1,背景 最近項(xiàng)目集成客服系統(tǒng)涉及到推送消息, app 進(jìn)行整體消息改版,所有我把項(xiàng)目中的推送相關(guān)的代碼和邏輯整合...
    崔可一閱讀 2,641評(píng)論 5 8
  • Swift1> Swift和OC的區(qū)別1.1> Swift沒有地址/指針的概念1.2> 泛型1.3> 類型嚴(yán)謹(jǐn) 對(duì)...
    cosWriter閱讀 11,689評(píng)論 1 32
  • 介紹一下iOS10的通知新功能,用戶體驗(yàn)的提升和開發(fā)者能夠發(fā)揮的地方非常多,使得iOS更具有競(jìng)爭(zhēng)力。 1.iOS ...
    F麥子閱讀 4,108評(píng)論 3 4
  • 轉(zhuǎn)載自:iOS10里的通知與推送 原文 通知和推送是一種東西么? iOS 10通知 推送 圖1為通知,圖2為推送也...
    路漫漫其修遠(yuǎn)兮Wzt閱讀 1,102評(píng)論 0 1

友情鏈接更多精彩內(nèi)容