2017-04-07 49 views
1

如何使用Firebase的FCM功能在我的應用中顯示橫幅廣告?我能夠通過蘋果提供的委託方法來接收和顯示橫幅通知:如何使用FCM觸發橫幅通知?

​​

但是,一旦我嘗試使用FCM,這種方法不再調用。相反,它是這個方法接收通知信息:

extension FirebaseNotificationManager: FIRMessagingDelegate { 
    func applicationReceivedRemoteMessage(_ remoteMessage: FIRMessagingRemoteMessage) { 
    let appData = remoteMessage.appData 
    appData.forEach { print($0) } 
    } 
} 

我可以得到appData的打印輸出,但我不知道如何實際顯示的旗幟警報。

任何幫助表示讚賞!

回答

0

的研究和實驗一整天后,我得出的結論是連接到火力地堡FCM是沒有必要的,對於這種情況。

如果您連接到FCM,則需要依靠Firebase的applicationReceivedRemoteMessage方法來處理傳入的推送通知。我仍然無法弄清楚如何通過該方法顯示橫幅通知。

但是,主要目標是訪問由推送通知發送的鍵值對。沒有必要通過Firebase的自定義對象來訪問這些對象。

每個UNNotification對象都有一個userInfo字典(雖然這是相當嚴重的嵌套):

let userInfo = response.notification.request.content.userInfo 

這將包含在FIRMessagingRemoteMessage發現了同樣的信息:

let appData = remoteMessage.appData 
0

我正在使用這適用於iOS 10併爲我工作。

- (void)userNotificationCenter:(UNUserNotificationCenter *)center 
    willPresentNotification:(UNNotification *)notification 
    withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler 
{ 
     NSDictionary *userInfo = notification.request.content.userInfo; 

     // Print full message. 
     NSLog(@"%@", userInfo); 

// Change this to your preferred presentation option 
     completionHandler(UNNotificationPresentationOptionAlert); 

} 
+0

使用IOS 10也。出於某種原因,在我嘗試使用FCM之後,該方法從未被調用。 –