簡體   English   中英

永遠不會調用ReceivedRemoteNotification和DidReceiveRemoteNotification

[英]ReceivedRemoteNotification and DidReceiveRemoteNotification never get called

我們在應用程序中實現了遠程推送通知。 我們想要實現的是,當我們的應用程序在后台運行時,將出現一個遠程通知,用戶單擊該通知,我們將根據通知信息執行一些任務。 我注意到,當應用程序在后台運行時,當有通知傳入時,在Appdelegate中,永遠不會調用DidReceiveRemoteNotification和ReceivedRemoteNotification。 我無法從userInfo獲取通知。 有人遇到過這個問題嗎? 這是錯誤嗎? 任何幫助是極大的贊賞!

謝謝李昌

確保您在真實設備上進行測試。 您需要在info.plist

<key>UIBackgroundModes</key>
<array>
  <string>remote-notification</string>
</array>

這在您的Entitlements.plist

<dict>
  <key>aps-environment</key>
  <string>development</string>
</dict>

讓您的AppDelegate類實現以下接口: IUNUserNotificationCenterDelegate

嘗試添加它,看看它是否被調用:

    [Export("userNotificationCenter:willPresentNotification:withCompletionHandler:")]
    public void WillPresentNotification(UNUserNotificationCenter center, 
                           UNNotification notification, 
                           Action<UNNotificationPresentationOptions> completionHandler)
    {
        completionHandler?.Invoke(UNNotificationPresentationOptions.Alert);
    }

    public override void DidReceiveRemoteNotification(UIApplication application, 
              NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
    {
        //BACKGROUND
        //handleNotification(userInfo);
        completionHandler(UIBackgroundFetchResult.NewData);
    }

另外,在Apple開發人員門戶上,請確保您已為KeysApple Push Services證書添加了某些內容,並且在對應用程序進行簽名的供應配置文件中具有該證書。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM