我的問題可能是壞的,但我找不到任何答案的任何地方,我迷路了......在iOS中豐富的推送通知使用數據與FCM
所以我想顯示了豐富的通知在iOS 10+中擁有不錯的圖像。
爲此,我使用FCM和UNNotificationServiceExtension,如果我理解正確,應該獲取數據有效負載,找到圖像URL並在修改UNNotificationContent之前加載它。
我遇到的問題是我無法掌握這個「數據」。
什麼我發送給FCM如下:
{
"to": "device_token",
"content_available": true,
"mutable_content": true,
"badge" : 9,
"notification": {
"title": "You still need the iPhone ?",
"body": "Give it back if you finished you tests !"
},
"data": {
"message": "test !",
"mediaUrl": "http://usr.audioasylum.com/images/2/20352/Cat_and_rose.jpg"
},
"priority": "high"
}
我得到的電話是:
{
aps = {
alert = {
body = "Give it back if you finished you tests !";
title = "You still need the iPhone ?";
};
"content-available" = 1;
"mutable-content" = 1;
};
"gcm.message_id" = "0:1489054783357873%1ee659bb1ee659bb";
mediaUrl = "http://usr.audioasylum.com/images/2/20352/Cat_and_rose.jpg";
message = "Offer!";
}
據我瞭解,在mediaURL和消息應該結束了「aps」,而不是外部,這就是爲什麼我無法在擴展中找到它們的原因。
和擴展我進去:(我把它分解上昏迷了更多可讀性)
<UNNotificationRequest: 0x117d3c170;
identifier: FDC13B60-FE5A-40C6-896D-06D422043CCE
content: <UNNotificationContent: 0x117d3a650; title: You still need the iPhone ?
subtitle: (null)
body: Give it back if you finished you tests !
categoryIdentifier:
launchImageName:
peopleIdentifiers:()
threadIdentifier:
attachments:()
badge: (null)
sound: (null)
hasDefaultAction: YES
shouldAddToNotificationsList: YES
shouldAlwaysAlertWhileAppIsForeground: NO
shouldLockDevice: NO
shouldPauseMedia: NO
isSnoozeable: NO
fromSnooze: NO
darwinNotificationName: (null)
darwinSnoozedNotificationName: (null)
trigger: <UNPushNotificationTrigger: 0x117d3fe90; contentAvailable: YES
mutableContent: YES>>
是這個問題我怎麼發信息與FCM,或者我找回它們的方式嗎?也許這是我對待他們的方式?
一如既往,感謝您的幫助!
編輯:爲接收器添加的代碼(這只是在擴展打印)
@interface NotificationService()
@property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
@property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;
@end
@implementation NotificationService
- (void) didReceiveNotificationRequest: (UNNotificationRequest *) request
withContentHandler: (void (^)(UNNotificationContent *_Nonnull))contentHandler
{
self.contentHandler = contentHandler;
self.bestAttemptContent = [request.content mutableCopy];
NSLog(@"------------------- %@ -------------------", request);
// Modify the notification content here...
self.bestAttemptContent.title = [NSString stringWithFormat:@"%@ [modified]", self.bestAttemptContent.title];
self.bestAttemptContent.body = [NSString stringWithFormat:@"%@", request.content];
self.contentHandler(self.bestAttemptContent);
}
嗨。如果您可以發佈您的代碼片段來接收郵件,我認爲這將有助於社區。 :) –
完成,但它確實只是代碼示例中的一個打印:) – SeikoTheWiz
嗨@SeikoTheWiz對不起,我在這裏沒有太多的幫助。我也在我的答案[這裏](http://stackoverflow.com/a/42263795/4625829)中看到了你的評論(與這篇文章有關嗎?)。我會嘗試環顧四周,看看我在這裏找到了什麼(但不能承諾任何)。有一件事引起了我的注意,儘管目前爲止,'badge'參數應該在'notification'中。無論如何,你希望解釋「數據」有效載荷的行爲是怎樣的,對吧?爲什麼數據出現在「aps」之外? –