【发布时间】: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 中设置
谁能指出我正确的方向?谢谢!
【问题讨论】:
-
使用了 VOiP 通知。检查它:stackoverflow.com/questions/48581495/…
-
那也没用。但我不应该这样做吗?如果我启用了后台模式,它意味着调用该函数?
标签: c# ios xamarin.forms xamarin.ios apple-push-notifications