Xamarinフォームでプッシュ通知を使用するのに苦労しています。XamarinフォームAzure通知ハブを使用したプッシュ通知
私はthisチュートリアルに従っていますが、そのチュートリアル自体は古くなっているようです。
私は現在、現時点でiOSに特に関心があります。ここで私がやったことは次のとおりです:
私はAzureでApp Serviceをセットアップし、そのためのNotification Hubを作成しました。 AppleデベロッパーセンターからAPNS証明書を作成し、Appleプッシュ通知の必要に応じて通知ハブにアップロードしました。私は自分のデバイス上で実行するためにアプリケーションに署名するために必要なプロビジョニングプロファイル証明書を持っています。ここで
は私AppDelegateクラスのコードです:
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();
}
}
私は問題がどこか
Push push = AppContainer.MobileServiceClient.GetPush();
ラインは基本的にこの
var client = new MobileServiceClient(APIConstants.PUSH_NOTIFICATION_URL);
のラッパーであることを、このラインであることを疑います
これは、アプリケーションのどこかで行われます。間違ったURLを使用している可能性がありますが、何も分かりません。私はApp ServiceとNotification HubエンドポイントのURLを試してみました。さまざまな形で、つまりプロトコルの削除、末尾のスラッシュの削除などを行いました。
何も動いていないようにみえて、私は私が言ったように私は
:)私の髪を引き裂くよ時点でよ、チュートリアルでは、時代遅れのように思われ、私が見つけた他のチュートリアル同じように欠けている。 Azure Portal経由でNotification HubのTest Sendオプションで直接テストしていますが、何もデバイスに送信されない、または少なくともデバイスが通知を表示していません。
何か助けが素晴らしい、またはあなたがもっと役に立つチュートリアルをどこかでオンラインで見つけたら、私にリンクをドロップしてください。