No Devices Registered with Parse Push and Xamarin IOS

偶尔善良 提交于 2019-12-06 08:52:40

I'm going through the same issue as well. I've followed the tutorial and recreated provisioning profiles, .p12 etc just as you have. Still no luck. I went the manual way following the example here - https://www.parse.com/docs/rest/guide/#push-notifications-uploading-installation-data and registered my device via a curl command:

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

After doing that I immediately saw my device as registered. I tried to send a push notification but have not received it yet. Something tells me that there's an issue with the Xamarin installation or with certificates/provisioning profiles. I'm still working on this, if I resolve it I will update.

Edit 1: I found out that if you uninstall the app you're working on and re-install then your device token changes. Anyway so I tried something different again, I fired up my app and ran it in debug mode via xamarin. I grabbed the new device token and issued that curl command again. Parse now tells me I have two devices registered. I hit the home button on my app and told parse to fire off a push notification and I received it. So now I'm investigating if the app is properly registering with parse. It seems like it tries to communicate but there might be an error somewhere and I'm not sure what it might be.

Update: So I finally got my device to register but going a totally different way. Here's what my RegisteredForRemoteNotifications looks like now. (Note: I am using Parse 1.5.5 as newer versions did not work at the time of this writing. Currently the newest version is 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);
            }
        });
    }

I'd still like to know why we can't do

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

  installation.SaveAsync();
}

But for now I have something that works.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!