1

我爲我的推送通知使用Firebase雲消息傳遞,後者在其後端使用APN。只有當應用程序在後臺才隱藏APN通知?

當應用程序在前景didReceiveRemoteNotification被調用和通知不顯示,這是完美的。

當應用程序是遇難didReceiveRemoteNotification不被調用,但通知顯示,這也沒關係。

但是,當應用程序處於背景時,兩個didReceiveRemoteNotification都被調用並顯示通知。我如何隱藏它並保持只有didReceiveRemoteNotification被調用?

這裏是我的有效載荷的樣子:

$fields = array(
    'registration_ids' => $tokens, 
    'data' => $message, 
    'content_available' => true, 
    'priority' => 'high', 
    'notification' => array('body' => 'notifbody', 'title' => 'testtitle', 'sound' => 'default') 
    ); 

回答

1

試試這個。

- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { 
     UIApplicationState state = [application applicationState]; 
     // user tapped notification while app was in background 
    if (state == UIApplicationStateInactive || state == UIApplicationStateBackground) { 
     // go to screen relevant to Notification content 
    } else { 
     // App is in UIApplicationStateActive (running in foreground) 
     // perhaps show an UIAlertView 
    } 
} 

其次, 當你調用方法- (空)registerForRemoteNotificationTypes:(UIRemoteNotificationType)類型你應該指出適當類型的參數。如果您想在系統收到設備的推送通知時顯示警報,則應通過UIRemoteNotificationTypeAlert

此外,您可以合併類型並將其傳遞給該參數:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge。

刪除警報,如果你不想從上面得到警報。

希望它能幫助你。

謝謝。

+0

這種方法在我的代碼中是空的,我沒有自己展示任何東西,APN生成並顯示通知 –

+0

您是否在談論通知中心裏來自iOS頂部的通知? @Gintas_ –

+0

是的,這是正確的 –

相關問題