2016-07-19 13 views
1

私は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のエラーを気付いた。コンソール。

私は何度も読んできましたが、私のプロジェクト/ソリューションをきれいにして再構築しましたが、これは数回しましたが、役に立たないものです。

私はどこを探し続けるべきかについては本当に断りません。

+0

デバイス/シミュレータからアプリケーションを手動で削除して、xs/vsで再デプロイして再テストできるようにしてください。 – SushiHangover

+0

あなたの提案をお寄せいただきありがとうございます。 「AppNameはあなたに通知を表示したい」というアプリケーションの起動時に画面を表示しますが、「RegisteredForRemoteNotifications」と「FailedToRegisterForRemoteNotifications」のどちらも呼び出されません。 –

+0

私はこの同じ問題に関連する何かを見つけたと思う、[right here](http://stackoverflow.com/a/38454917/6470327) –

答えて

1

今日、この問題を解決しようとするいくつかの時間を無駄にした後、私が引用され、this answer出くわし:

を長く掘る後、私が何らかのエラーや updationに2016年7月19日にそれを発見しましたAppleの終わりに、 didRegisterForRemoteNotificationsWithDeviceTokenメソッドは、インターネット接続、デバイス、 などのすべての条件が完璧であっても、 が呼び出されませんでした。

あまりにも他のアプリで見てください確認するために確認 https://forums.developer.apple.com/thread/52224

のために、このリンクを参照してください。私は 数時間を無駄にしたが、誰かを助けることを願っている。ありがとう。

アップルがこの問題を解決するまで待つだけでいいと思う。 2016年7月20日


編集:
私のコードには何も変更せずに、それは一晩再び働き始めました。 Appleがこの問題を解決したと仮定することは安全です。

2

私は昨日同じ問題を抱えていました。今日私はコードを変更せずにもう一度試してみました。この問題で約5時間を費やし、アップルの開発者サイトを検索してアップルのサービスに問題がないかどうかを確認し、何も見つけられませんでした。絶対に迷惑!

結局のところ、Appleによって引き起こされたエラーが今日解決されているようです。

関連する問題