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

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

问题描述

我试图建立与解析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 /文档/ DOTNET /指南#推通知,推入式xamarin-IOS
https://www.parse.com/apps/quickstart#parse_push/ios / xamarin /现有
<一href=\"https://developer.xamarin.com/guides/cross-platform/application_fundamentals/notifications/ios/remote_notifications_in_ios/\" rel=\"nofollow\">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这样的认识,

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

但仍然没有运气。

But still no luck.

我添加了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中和省轮廓相一致。

但我想这是不是与供给曲线的一个问题,因为该应用程序的注册通知,

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

为什么不同意解析?

我是什么失踪?

推荐答案

我经历了同样的问题也是如此。我跟着教程,并重新调配型材的.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命令。解析现在告诉我,我已经注册了两个设备。我打的home键上我的应用程序,并告诉解析火了推送通知,我收到了。所以,现在我们正在调查,如果应用程序被正确地解析注册。好像它试图沟通,但有可能是一个错误的地方,我不知道它可能是什么。

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貌似现在。 (注:我使用的解析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天全站免登陆