没有使用Parse Push和Xamarin IOS注册的设备

我正尝试使用Parse Push和Xamarin IOS设置推送通知。 我遵循这些指南:

https://www.parse.com/docs/dotnet/guide#push-notifications-push-on-xamarin-ios https://www.parse.com/apps/quickstart#parse_push/ios/xamarin/existing https: //developer.xamarin.com/guides/cross-platform/application_fundamentals/notifications/ios/remote_notifications_in_ios/ https://groups.google.com/forum/#!topic/parse-developers/65WAfRIiEnA

从我的理解,我修改了我的AppDelegate,

我把这个添加到构造函数中:

ParseClient.Initialize("MY APP ID", "MY DOT NET KEY"); 

用适当的钥匙。

我将其添加到FinishedLaunching方法

 if (Convert.ToInt16(UIDevice.CurrentDevice.SystemVersion.Split('.')[0].ToString()) < 8) { UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound; UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(notificationTypes); } else { UIUserNotificationType notificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound; var settings = UIUserNotificationSettings.GetSettingsForTypes(notificationTypes, new NSSet(new string[] { })); UIApplication.SharedApplication.RegisterUserNotificationSettings(settings); UIApplication.SharedApplication.RegisterForRemoteNotifications(); } // Handle Push Notifications ParsePush.ParsePushNotificationReceived += (object sender, ParsePushNotificationEventArgs args) => { Utils.Log("Push!"); }; 

然后我添加了适当的覆盖:

 public override void DidRegisterUserNotificationSettings(UIApplication application, UIUserNotificationSettings notificationSettings) { application.RegisterForRemoteNotifications(); } public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken) { ParseInstallation installation = ParseInstallation.CurrentInstallation; installation.SetDeviceTokenFromData(deviceToken); installation.SaveAsync(); } public override void FailedToRegisterForRemoteNotifications (UIApplication application , NSError error) { new UIAlertView("Error registering push notifications", error.LocalizedDescription, null, "OK", null).Show(); } public override void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo) { // We need this to fire userInfo into ParsePushNotificationReceived. ParsePush.HandlePush(userInfo); } 

但是还是没有运气。

我在RegisteredForRemoteNotifications方法中添加了一个断点,它确实被调用,所以我显然注册了通知,但是当我尝试从parsing发送推送通知时,它告诉我“没有注册设备”。

我已经尝试过的事情:

  • 检查供应configuration文件是为推送通知设置的。
  • 删除远程和本地的所有configuration文件,然后重新生成它们。
  • 确保构build使用新的configuration文件。
  • 重新生成.p12文件并重新上载parsing。
  • 检查我的包标识符在Info.plist和provconfiguration文件中是一致的。

但我可以想象这不是configurationconfiguration文件的问题,因为应用程序正在注册通知,

为什么parsing不同意?

我错过了什么?

我也遇到同样的问题。 我已经按照教程,重新创buildconfiguration文件,.p12等。 仍然没有运气。 我按照这里的示例去手动方式 – https://www.parse.com/docs/rest/guide/#push-notifications-uploading-installation-data并通过一个curl命令注册我的设备&#xFF1A;

 curl -X POST \ -H "X-Parse-Application-Id: <Your Parse app ID> " \ -H "X-Parse-REST-API-Key: <Your parse REST API key>" \ -H "Content-Type: application/json" \ -d '{ "deviceType": "ios", "deviceToken": "<Your device token>", "channels": [ "" ] }' \ https://api.parse.com/1/installations 

这样做后,我立即看到我的设备注册。 我试图发送推送通知,但尚未收到它。 有些东西告诉我,Xamarin安装或证书/供应configuration文件有问题。 我仍在这个工作,如果我解决它,我会更新。

编辑1:我发现,如果你卸载你正在使用的应用程序,并重新安装,那么你的设备令牌更改。 无论如何,所以我尝试了不同的东西,我打开了我的应用程序,并通过debugging模式通过xamarin运行。 我抓住了新的设备令牌,并再次发出curl命令。 现在parsing告诉我,我有两个设备注册。 我打我的应用程序的主页button,并告诉parsing发射推送通知,我收到了。 所以,现在我正在调查,如果应用程序正确注册parsing。 它似乎试图沟通,但可能有一个地方的错误,我不知道它可能是什么。

更新:所以我终于得到我的设备注册,但采取了完全不同的方式。 以下是我的RegisteredForRemoteNotifications现在的样子。 (注意: 我正在使用Parse 1.5.5,因为在写这篇文章的时候新版本没有工作,目前最新的版本是1.6.2)。

 public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken) { ParseObject obj = ParseObject.Create ("_Installation"); string dt = deviceToken.ToString ().Replace ("<", "").Replace (">", "").Replace (" ", ""); obj["deviceToken"] = dt; obj.SaveAsync ().ContinueWith (t => { if (t.IsFaulted) { using (IEnumerator<System.Exception> enumerator = t.Exception.InnerExceptions.GetEnumerator()) { if (enumerator.MoveNext()) { ParseException error = (ParseException) enumerator.Current; Console.WriteLine ("ERROR!!!: " + error.Message); } } } else { Console.WriteLine("Saved/Retrieved Installation"); var data = NSUserDefaults.StandardUserDefaults; data.SetString ("currentInstallation", obj.ObjectId); Console.WriteLine("Installation ID = " + obj.ObjectId); } }); } 

我仍然想知道为什么我们做不到

 public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken) { ParseInstallation installation = ParseInstallation.CurrentInstallation; installation.SetDeviceTokenFromData(deviceToken); installation.SaveAsync(); } 

但现在我有一些工作。