因此,我正在Xamarin IOS开发一个应用程序,并且需要发送推送通知以偶发地更新离线同步数据。但是,似乎DidReceiverEmoteNotification函数仅在应用在前景时运行!
我知道,如果该应用程序关闭,它将无法正常工作,但是在后台应该可以工作吗?该文档似乎也支持这一点。通过我自己的研究,我可以看到本机代码具有两个不同的DidreceivereMoteNotification的功能(DidreceivereMototeNotification和Didreceiveremotonotification: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 ":{" content-available ":1}}";
背景模式在info.plist中设置了
有人可以指向正确的方向吗?谢谢!
,所以我自己找到了答案。事实证明,iOS 11对于无声推动通知非常糟糕!
我正在使用iOS 11.1.x版本,它根本没有工作,我将手机升级到iOS 11.2.5,现在正常工作。
didReceivereMotOnotification函数被称为预期,并且在后台检索数据!
如果其他任何人都遇到了本机或Xamarin应用程序,请检查您的iOS版本!