- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- 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 方法中添加了一个断点,它确实被调用了,所以我显然是在注册通知,但是当我尝试从解析中发送推送通知时,它告诉我“没有设备注册”。
我尝试过的事情:
但我想这不是供应配置文件的问题,因为应用程序正在注册通知,
为什么 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/
我的团队正在使用 gerrit 代码审查,本质上这意味着默认的推送行为会绕过标准工作流程,因此我们需要使用 git push origin HEAD:refs/for/feature 来正确推送我们的
我是 assembly 新手,我正在使用 MASM。我看到这些代码行,想知道这之间有什么区别 a) push myVar b) push [myVar] c) push OFFSET myVar 我怎
美好的一天! 将镜像推送到docker hub时遇到一些问题。我的第一个软件版本: vagrant@debian-8-docker:~$ docker version Client version:
我有三个 Controller 一二三 .首先是navigationController的rootViewController。 在 SecondViewController ,我有一个名为 的协议(
我在这个 Google 教程的帮助下实现了一个 Web Push API: https://developers.google.com/web/fundamentals/getting-started
我有两个模式: var optionsSchema = new Schema({ locationname: String, locationnumber : String
我是 git 的新手并对其进行了测试。我已经能够克隆 friend 存储库进行小的本地更改并提交。 我现在想测试将我的本地更改推送到远程存储库,但不幸的是当我尝试进行推送时 $ git push <
我们正在公司讨论 git rebase 之后该做什么。在rebase之后,您需要将更改推送到远程origin,但是当git不允许时我们应该怎么做呢?实际上,我们正在讨论当分支已经被推送时我们最常用的两
我正在使用具有嵌入式 github 支持的新 IDE。在命令行本地,我可以成功地使用 git push orgin master 并更新 github。但是我的 IDE 使用带有 -v 标志的命令,这
我仍在阅读有关 RoR 的一些指南,我被困在 Deploying The Demo App 上 我遵循了说明: With the completion of the Microposts resour
我正在尝试创建一个可以将我的 git 存储库镜像到另一个存储库的脚本。一切正常,但它一直在说 [remote rejected] refs/pull/xx/head -> refs/pull/xx/h
我想了解使用 Tortoise SVN 构建过程的一些过程。主要是 我想知道你是否插入: 主线中继 QA 后的一个分支将其抓取到本地的工作副本中并测试该分支,然后一些构建推送该分支 我遇到的问题是我在
在谈论将消息推送到移动应用程序以触发 WAP 内容的下载时,似乎都使用了 WAP 推送和 SMS 推送这两个术语。 这些术语是指相同的机制还是具有不同的含义? 最佳答案 SMS Push 是告诉终端发
我只是想知道是否有人使用这种技术: 由于推送通知仅随 OS 3.0 一起提供,因此我一直在考虑使用电子邮件推送(Exchange、mobile.me)作为解决方法: 您可以注册一个 URL,例如。 m
我正在 build WP website using DIVI theme .应该被插入 dataLayer 的标签被默认的“未设置”值卡在某个地方。 为了推送我使用脚本的值: functi
我最近删除了xcode 6 beta 3并安装了xcode 6 beta 6 当我在终端输入gitpush时,这发生了 xcrun:错误: Activity 的开发人员路径(“/Application
我即将实现ionic-native Push Notifications .这可以在浏览器中运行吗?还是我需要安装 iOS/Android 模拟器? 最佳答案 除非您使用 Phonegap 推送服务器
Safari 12.1 是否支持服务 worker PWA 推送通知?我试过这个 demo在 iOS 上,但它仍然不适合我。 有机会得到它们吗?谢谢。 最佳答案 目前没有关于此功能的通信...Appl
目前我有很多 chrome 浏览器的推送订阅都是这样的方法, swr.pushManager.subscribe({userVisibleOnly: true}) .then(function
我需要 4 个过渡效果,但我只知道 2 个过渡效果,还有 2 个我不知道。我知道的 2 个过渡动画是: 过渡时下推: 并向下推过渡: 但
我是一名优秀的程序员,十分优秀!