Ich habe Probleme mit Push-Benachrichtigungen, die mit Xamarin Forms arbeiten, und ich würde mich über jede Hilfe freuen.Xamarin Forms Push-Benachrichtigungen mit Azure Notifications Hub
Ich habe this Tutorial gefolgt, die selbst scheint nicht mehr aktuell zu sein.
Ich bin speziell mit iOS im Moment betroffen. Hier ist, was ich getan habe:
Ich habe einen App-Service in Azure eingerichtet und einen Notification Hub für sie erstellt. Ich habe ein APNS-Zertifikat über mein Apple Developer Center erstellt und es in den Notification Hub hochgeladen, wie es für Apple Push-Benachrichtigungen erforderlich ist. Und ich habe das erforderliche Provisioning-Profilzertifikat, um die App auf meinem Gerät zu signieren. Hier
ist der Code in meiner AppDelegate Klasse:
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
var setup = new IOSAppContainerSetup();
LoadApplication (new App (setup));
// Register for push notifications.
var settings = UIUserNotificationSettings.GetSettingsForTypes(
UIUserNotificationType.Alert
| UIUserNotificationType.Badge
| UIUserNotificationType.Sound,
new NSSet());
UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
UIApplication.SharedApplication.RegisterForRemoteNotifications();
return base.FinishedLaunching (app, options);
}
public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
{
const string templateBodyAPNS = "{\"aps\":{\"alert\":\"$(messageParam)\"}}";
JObject templates = new JObject();
templates["genericMessage"] = new JObject
{
{"body", templateBodyAPNS}
};
// Register for push with your mobile app
Push push = AppContainer.MobileServiceClient.GetPush();
push.RegisterAsync(deviceToken, templates);
}
public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
{
UIAlertView avAlert1 = new UIAlertView("Notification", "Got something", null, "OK", null);
avAlert1.Show();
NSDictionary aps = userInfo.ObjectForKey(new NSString("aps")) as NSDictionary;
string alert = string.Empty;
if (aps.ContainsKey(new NSString("alert")))
alert = (aps[new NSString("alert")] as NSString).ToString();
//show alert
if (!string.IsNullOrEmpty(alert))
{
UIAlertView avAlert = new UIAlertView("Notification", alert, null, "OK", null);
avAlert.Show();
}
}
Ich vermute, dass das Problem mit dieser Linie irgendwo
Push push = AppContainer.MobileServiceClient.GetPush();
Diese Linie ist im Grunde ein Wrapper um diese
var client = new MobileServiceClient(APIConstants.PUSH_NOTIFICATION_URL);
Das ist woanders in der App gemacht. Ich vermute, ich könnte die falsche URL verwenden, aber nichts ist offensichtlich. Ich habe die URL des App Service und des Notification Hub-Endpunkts in verschiedenen Formen ausprobiert, d. H. Das Protokoll fallen lassen, die nachfolgenden Schrägstriche fallen lassen usw.
Nichts an einem Punkt zu arbeiten und ich bin scheint, wo ich mir die Haare aus :)
Als ob ich reißen sagte, scheint das Tutorial nicht mehr aktuell zu sein, und andere Tutorials, die ich gefunden habe, fehlen gleichermaßen. Ich teste dies direkt über die Option Test senden unter dem Notification Hub über das Azure-Portal, aber es wird nichts an das Gerät gesendet, oder das Gerät zeigt zumindest keine Benachrichtigung an.
Jede Hilfe wäre toll, oder wenn Sie irgendwo ein nützlicheres Tutorial online gefunden haben, dann schreiben Sie mir bitte einen Link.