i'm struggling push notifications working xamarin forms , i'd appreciate help.
i've been following this tutorial, appears out of date.
i'm concerned ios @ moment. here's i've done:
i've setup app service in azure , created notification hub it. i've created apns cert via apple developer centre , uploaded notification hub necessary apple push notifications. , have necessary provisioning profile certificate signing app run on device.
here code in appdelegate class:
public override bool finishedlaunching (uiapplication app, nsdictionary options) { global::xamarin.forms.forms.init (); var setup = new iosappcontainersetup(); loadapplication (new app (setup)); // register 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 push 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")) nsdictionary; string alert = string.empty; if (aps.containskey(new nsstring("alert"))) alert = (aps[new nsstring("alert")] nsstring).tostring(); //show alert if (!string.isnullorempty(alert)) { uialertview avalert = new uialertview("notification", alert, null, "ok", null); avalert.show(); } }
i suspect issue line somewhere
push push = appcontainer.mobileserviceclient.getpush();
that line wrapper around this
var client = new mobileserviceclient(apiconstants.push_notification_url);
which done elsewhere in app. suspect using wrong url, nothing obvious. i've tried url of app service , notification hub endpoint, , in various shapes, i.e. dropping protocol, dropping trailing slashes...etc.
nothing seems work , i'm @ point i'm tearing hair out :)
like said, tutorial seems out of date, , other tutorials i've found equally lacking. i'm testing directly via test send option under notification hub via azure portal, nothing gets sent device, or @ least device isn't showing notification.
any awesome, or if you've found more useful tutorial online somewhere please drop me link.
ok, seems tutorial referenced in question perhaps incorrect, or @ least incomplete. able push notifications working following code here, kindly given link mike on xamarin team.
cheers mike!
Comments
Post a Comment