[英]iOS Push Notifications don't adds to Notification Center
我在Xamarin.iOS平台上的iOS應用程序上實現了推送通知處理,但我的問題也適用於iOS本機。
由於某些原因,當我的應用程序處於后台模式時,我需要處理推送通知,因此我在項目中使用了后台模式和推送通知 。 另外,我在有效負載的aps字典中包含了值為1的內容可用鍵。 另外,我還包括了Alert , Badge和Sound鍵,因為我想向用戶顯示此推送通知並將其添加到Notification Center。
結果是在后台模式下收到推送通知后(當應用程序未激活時):
1)我使用DidReceiveRemoteNotification()方法處理推送通知的接收。
2)用戶看到通知從屏幕頂部作為橫幅向下滾動。
3)我更改應用程序圖標徽章計數器。
我的問題是在完成所有這些操作后, 推送通知不會添加到通知中心 。
據我了解,在使用DidReceiveRemoteNotification()方法處理推送通知后,iOS將此通知標記為已處理 ,並且不會將其添加到通知中心。 作為一種可能的解決方案,我可以創建本地通知,安排它們並將其添加到通知中心,但是用戶將再次看到通知從屏幕頂部作為橫幅滾動下來,這不好(看起來用戶收到2條通知,但是通知中心僅顯示1個)。
此行為的真正原因是什么,如何解決此問題?
您可以嘗試VoIP推送通知服務。
- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type
NSDictionary *payloadInfo = payload.dictionaryPayload;
[self showLocalNotificationWithInfo: payloadInfo];
}
- (void) showLocalNotificationWithInfo:(NSDictionary *)infoDict{
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = [NSDate date];
localNotification.alertBody = @"Your title message";
localNotification.soundName = @"YourSoundFileName.mp3";
localNotification.userInfo = userInfo;
localNotification.fireDate = [NSDate date];
localNotification.timeZone = [NSTimeZone systemTimeZone];
localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}
謝謝你們的回答。 我發現了這種現象的原因-問題出在推送通知正文中的徽章鑰匙上。 此項的值為0 ,這就是iOS將新通知標記為已讀且未將其添加到通知中心的原因。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.