【问题标题】:DidReceiveRemoteNotification is not called in background - Xamarin iOS - Push Notifications后台未调用 DidReceiveRemoteNotification - Xamarin iOS - 推送通知
【发布时间】:2018-02-17 10:30:45
【问题描述】:

所以我正在 Xamarin iOS 中开发一个应用程序,它需要发送推送通知来偶尔更新离线同步的数据。但是,似乎 DidReceiveRemoteNotification 函数仅在应用程序处于前台时运行!

我知道如果应用程序关闭它不会工作,但它应该在后台工作,对吧?文档似乎也支持这一点。通过我自己的研究,我可以看到 Native apple 代码有两个不同的 DidReceiveRemoteNotification 函数(didReceiveRemoteNotification 和 didReceiveRemoteNotification:fetchCompletionHandler),后者用于处理后台推送。我真的被卡住了,因为一切似乎都表明它应该调用它,但它并没有。

这是我的功能:

public override async void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> 
 completionHandler)

{

        Debug.WriteLine($"Notifcation Received - {userInfo.ToString()}");

        //Call to an empty Azure function to prove it is being called!
        //This allows me to check whether or not this code is eecuted without breakpoints in VS

         using (HttpClient client = new HttpClient()) 
            await client.GetAsync(FUNCTION_URL);


        //.. My code to pull latest data here

        completionHandler(UIBackgroundFetchResult.NewData);
}

我发送的只是一个简单的: "{\"aps\": {\"内容可用\": 1 }}";

后台模式也在 info.plist 中设置

谁能指出我正确的方向?谢谢!

【问题讨论】:

标签: c# ios xamarin.forms xamarin.ios apple-push-notifications


【解决方案1】:

所以我自己找到了答案。事实证明,IOS 11 对于无声推送通知来说非常糟糕!

我使用的是 iOS 11.1.x 版本,但它根本不工作,我将手机升级到 iOS 11.2.5,现在它可以正常工作了。

DidReceiveRemoteNotification 函数正在按预期调用,并且正在后台检索数据!

如果其他人在使用本机或 xamarin 应用程序时遇到此问题,请检查您的 iOS 版本!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-30
    • 2020-06-14
    • 2013-01-21
    • 2018-06-18
    • 2014-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多