没有向 Parse Push 和 Xamarin IOS 注册的设备 [英] No Devices Registered with Parse Push and Xamarin IOS

查看:17
本文介绍了没有向 Parse Push 和 Xamarin IOS 注册的设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to set up push notifications with Parse Push and Xamarin IOS. I have followed these guides:

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

根据我对那些我修改我的 AppDelegate 的理解,

From my understanding of those I modified my AppDelegate as such,

我将它添加到构造函数中:

I added this to the constructor:

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

使用适当的键.

然后我将它添加到 FinishedLaunching 方法中

And I added this to the FinishedLaunching method

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!");
};

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

Then I added the appropriate overrides:

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 方法中添加了一个断点,它确实被调用,所以我显然是在注册通知,但是当我尝试从解析发送推送通知时,它告诉我没有注册设备".

I added a breakpoint in the RegisteredForRemoteNotifications method and it does get called so I am apparently registering for notifications but when I try and send a push notification from parse it tells me "No Devices Registered".

我尝试过的事情:

  • 检查配置文件是否设置了推送通知.
  • 删除所有远程和本地配置文件,然后重新生成它们.
  • 通过构建确保使用新的配置文件.
  • 重新生成 .p12 文件并重新上传以进行解析.
  • 在 Info.plist 和 prov 配置文件中检查我的包标识符是一致的.

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

But I would imagine it is not an issue with the provisioning profiles because the App is registering for notifications,

为什么 Parse 不同意?

Why does Parse Disagree?

我错过了什么?

推荐答案

我也遇到了同样的问题.我已经按照教程重新创建了配置文件、.p12 等,就像你一样.仍然没有运气.我按照此处的示例手动操作 - https://www.parse.com/docs/rest/guide/#push-notifications-uploading-installation-data 并通过 curl 命令注册我的设备:

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

这样做后,我立即看到我的设备已注册.我尝试发送推送通知,但尚未收到.有人告诉我 Xamarin 安装或证书/配置文件存在问题.我还在努力解决这个问题,如果我解决了,我会更新.

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.

编辑 1:我发现如果您卸载正在使用的应用程序并重新安装,则您的设备令牌会发生变化.无论如何,我再次尝试了一些不同的东西,我启动了我的应用程序并通过 xamarin 在调试模式下运行它.我抓住了新的设备令牌并再次发出 curl 命令.Parse 现在告诉我我注册了两个设备.我点击了我的应用程序上的主页按钮并告诉 parse 发出推送通知,我收到了它.所以现在我正在调查应用程序是否正确注册了 parse.它似乎尝试进行通信,但某处可能出现错误,我不确定它可能是什么.

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.

更新:所以我终于让我的设备注册了,但采用了完全不同的方式.这是我的 RegisteredForRemoteNotifications 现在的样子.(注意:我使用的是 Parse 1.5.5,因为在撰写本文时较新的版本不起作用.目前最新版本是 1.6.2.)

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.

这篇关于没有向 Parse Push 和 Xamarin IOS 注册的设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆