gpt4 book ai didi

c# - DidReceiveRemoteNotification 未在后台调用 - Xamarin iOS - 推送通知

转载 作者:行者123 更新时间:2023-11-29 11:36:37 24 4
gpt4 key购买 nike

所以我正在 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中设置

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

最佳答案

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

我使用的是 iOS 11.1.x 版本,但它根本无法运行,我将手机升级到 iOS 11.2.5,现在它运行完美。

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

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

关于c# - DidReceiveRemoteNotification 未在后台调用 - Xamarin iOS - 推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48840361/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com