私はXamarin.iOSアプリケーションのプッシュ通知を実装しようとしています。私は複数のGetting Started guidesと他のチュートリアルをフォローしましたが、私はデバイストークンをもう入手できないようです。それは前に働いていて、重大な変更はありませんでしたが、私はここで問題を突き止めることはできません。リモート通知の登録が黙って失敗する
AppDelegate.cs
[Register("AppDelegate")]
public class AppDelegate : UIApplicationDelegate, IReceiverDelegate
{
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
var gcmConfig = Google.GoogleCloudMessaging.Config.DefaultConfig;
gcmConfig.ReceiverDelegate = this;
Google.GoogleCloudMessaging.Service.SharedInstance.Start(gcmConfig);
var notTypes = UIUserNotificationType.Sound | UIUserNotificationType.Alert | UIUserNotificationType.Badge;
var settings = UIUserNotificationSettings.GetSettingsForTypes(notTypes, null);
UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
UIApplication.SharedApplication.RegisterForRemoteNotifications();
// ... Other application stuff
return true;
}
public override void OnActivated(UIApplication application)
{
Google.GoogleCloudMessaging.Service.SharedInstance.Connect(error =>
{
if (error != null)
{
Console.WriteLine("GCM Connect error: " + error);
}
});
}
public override void DidEnterBackground(UIApplication application)
{
Google.GoogleCloudMessaging.Service.SharedInstance.Disconnect();
}
private NSData DeviceToken;
// This function does NOT get called anymore
public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
{
this.DeviceToken = deviceToken;
var config = Google.InstanceID.Config.DefaultConfig;
Google.InstanceID.InstanceId.SharedInstance.Start(config);
var options = new NSMutableDictionary();
options.SetValueForKey(DeviceToken, Google.InstanceID.Constants.RegisterAPNSOption);
options.SetValueForKey(new NSNumber(true), Google.InstanceID.Constants.APNSServerTypeSandboxOption);
Google.InstanceID.InstanceId.SharedInstance.Token(
GCMConnection.SenderId,
Google.InstanceID.Constants.ScopeGCM,
options,
(token, error) => {
if (error == null)
{
// ... Send token to our API
PubSub.SharedInstance.Subscribe(token, "/topics/global", new NSDictionary(), delegate { });
return;
}
Console.WriteLine("Error getting GCM token: " + error);
// Handle error
});
}
public override void FailedToRegisterForRemoteNotifications(UIApplication application, NSError error)
{
Console.WriteLine(error);
}
public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
{
// Handle notification here
Google.GoogleCloudMessaging.Service.SharedInstance.AppDidReceiveMessage(userInfo);
}
[Export("didDeleteMessagesOnServer")]
public void DidDeleteMessagesOnServer()
{
// ...
}
[Export("didSendDataMessageWithID:")]
public void DidSendDataMessage(string messageID)
{
// ...
}
[Export("willSendDataMessageWithID:error:")]
public void WillSendDataMessage(string messageID, NSError error)
{
// ...
}
}
私は簡潔にするためにいくつかのポイントにコードを短縮しました。
昨日、ある時点で私は自分のトークンを正しく取得していましたが、私が得るはずだった通知の一部を受け取ることさえできました。 FinishedLaunching
メソッドに何も変更せずに、理由についてのフィードバックなしに突然動作を停止しました。
私はそれを修正しようとしたが、私はすべての固定以来(たとえば、私はGoogleService-Info.plist
ファイルを忘れてしまった)GCMに関連するConsole.Logのエラーを気付いた。コンソール。
私は何度も読んできましたが、私のプロジェクト/ソリューションをきれいにして再構築しましたが、これは数回しましたが、役に立たないものです。
私はどこを探し続けるべきかについては本当に断りません。
デバイス/シミュレータからアプリケーションを手動で削除して、xs/vsで再デプロイして再テストできるようにしてください。 – SushiHangover
あなたの提案をお寄せいただきありがとうございます。 「AppNameはあなたに通知を表示したい」というアプリケーションの起動時に画面を表示しますが、「RegisteredForRemoteNotifications」と「FailedToRegisterForRemoteNotifications」のどちらも呼び出されません。 –
私はこの同じ問題に関連する何かを見つけたと思う、[right here](http://stackoverflow.com/a/38454917/6470327) –