我目前正在处理xamarin形式的ios应用程序推送通知。如果应用程序已关闭(滑动),则DidReceiveRemoteNotification不会调用。
数据有效负载类似于下面的服务器端,
私有无效SendMessage(string [] MessageTokenArray,字符串TextMessage)
{
var dataIOS = new
{
// to = MessageToken,
registration_ids = MessageTokenIOS,
content_available = true,
priority = "high",
data = new
{
body = body1,
title = eventname,
click_action = "OPEN_ACTIVITY_1",
priority = "high",
tag = "\"1\""
},
notification = new
{
title = eventname,
text = TextMessage,
sound = 1,
vibrate = 1,
},
};
SendNotificationn(dataIOS);
}
}
在xamarin ios中
公共重写布尔FinishedLaunching(UIApplication应用,NSDictionary选项) {
CrossFirebasePushNotification.Current.RegisterForPushNotifications();
FirebasePushNotificationManager.Initialize(options, true);
FirebasePushNotificationManager.CurrentNotificationPresentationOption = UNNotificationPresentationOptions.Alert | UNNotificationPresentationOptions.Badge | UNNotificationPresentationOptions.Sound;
CrossFirebasePushNotification.Current.OnTokenRefresh += async (s, p) =>
{
//save token in server db
};
CrossFirebasePushNotification.Current.OnNotificationReceived += async (s, p) =>
{
//save data in local db
};
CrossFirebasePushNotification.Current.OnNotificationOpened += (s, p) =>
{
//do something
};
return base.FinishedLaunching(app, options);
}
公共重写void DidReceiveRemoteNotification(UIApplication应用程序,NSDictionary userInfo,操作完成处理程序)
{ FirebasePushNotificationManager.DidReceiveMessage(userInfo);
completionHandler(UIBackgroundFetchResult.NewData);
}