gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:12:06 25 4
gpt4 key购买 nike

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

我尝试过的事情:

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

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

为什么 Parse 不同意?

我错过了什么?

最佳答案

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

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 安装或证书/配置文件存在问题。我仍在努力解决这个问题,如果我解决了它,我会更新。

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

更新:所以我终于让我的设备注册了,但采用了完全不同的方式。这是我的 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();
}

但现在我有一些有用的东西。

关于c# - 没有使用 Parse Push 和 Xamarin IOS 注册的设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33041335/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com