CrossPushNotificationListener
クラスにIPushNotificationListener
を実装しました。 READMEファイルに示唆されているとおりです。XamarinフォームでCrossPushNotificationプラグインを実装する方法は?
public class CrossPushNotificationListener : IPushNotificationListener
{
void IPushNotificationListener.OnError(string message, DeviceType deviceType)
{
Application.Current.MainPage.DisplayAlert("error", message, "ok");
}
void IPushNotificationListener.OnMessage(JObject values, DeviceType deviceType)
{
Application.Current.MainPage.DisplayAlert("message", values.ToString(), "ok");
}
void IPushNotificationListener.OnRegistered(string token, DeviceType deviceType)
{
Application.Current.MainPage.DisplayAlert("token", token, "ok");
}
void IPushNotificationListener.OnUnregistered(DeviceType deviceType)
{
Application.Current.MainPage.DisplayAlert("unregistered", "", "ok");
}
bool IPushNotificationListener.ShouldShowNotification()
{
Application.Current.MainPage.DisplayAlert("should show notification", "", "ok");
return true;
}
}
iOSのAppDelegateでは、私はCrossPushNotificationプラグインを初期化します。その後
public override void FailedToRegisterForRemoteNotifications(UIApplication application, NSError error)
{
if (CrossPushNotification.Current is IPushNotificationHandler)
{
((IPushNotificationHandler)CrossPushNotification.Current).OnErrorReceived(error);
}
}
public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
{
if (CrossPushNotification.Current is IPushNotificationHandler)
{
((IPushNotificationHandler)CrossPushNotification.Current).OnRegisteredSuccess(deviceToken);
}
}
public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
{
if (CrossPushNotification.Current is IPushNotificationHandler)
{
((IPushNotificationHandler)CrossPushNotification.Current).OnMessageReceived(userInfo);
}
}
public override void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo)
{
if (CrossPushNotification.Current is IPushNotificationHandler)
{
((IPushNotificationHandler)CrossPushNotification.Current).OnMessageReceived(userInfo);
}
}
ユーザーが/登録アプリケーションにログインします、それを入力した後、私の共有コードでは、:PushNotificationApplicationDelegate.txt.pp
ファイルに示すように
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
CrossPushNotification.Initialize<CrossPushNotificationListener>();
LoadApplication(new Origination.App());
return base.FinishedLaunching(app, options);
}
は、私は、適切なオーバーライドでAppDelegateにも拡張していますホーム画面、私は電話する:
CrossPushNotification.Current.Register();
私はこのメソッドが実行されていると知っているので、私はアクセス許可を要求するアラートを得る。しかし、CrossPushNotificationListener
に実装されているIPushNotificationListener
インターフェイスのメソッドはどれも呼び出されません。
私はここで何が欠けていますか?
ありがとうございます。
?最初にデバイスが正しく登録され、プッシュ通知がAppleプッシュ通知サービスに配信されていることを確認する必要があります。 – hankide
CrossPushNotificationListenerのメソッドが呼び出されることはないため、デバイストークンが取得されません。AppDelegateのメソッドもありません。私は許可アラートの要求を取得すると、レジスタが発生します。このビットは私をさらに混乱させています... – nmdias