我有一个尚未发布的正在进行的应用程序,除了我的后端之外我依赖Parse for Push,但是由于Parse正在关闭,因此它没有任何意义用Parse释放它然后稍后更改。
无论如何,现在我转移到iOS的GCM,从我看到的代码下面你只需注册推送通知(正常的iOS方式)然后一旦你得到令牌你用GCM注册它(就像以前一样) Parse),但最大的区别是,当我强制关闭应用程序时,从未收到推送通知,但是当我有Parse并且我强制关闭应用程序时,我发送推送通知我仍然得到它,看着什么'在Parse的开源SDK下面(我无法理解所有内容,但我发现没有使用PushKit),在网上几个类似的问题中提出了Pushkit。但是如何实现这一目标还没有明确的解决方案。
这是我在注册推送时所做的事情:
// Register for remote notifications
UIUserNotificationType allNotificationTypes =
(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge);
UIUserNotificationSettings *settings =
[UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
然后:
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSLog(@"Application registered for remote notification");
GGLInstanceIDConfig *instanceIDConfig = [GGLInstanceIDConfig defaultConfig];
instanceIDConfig.delegate = self;
[[GGLInstanceID sharedInstance] startWithConfig:instanceIDConfig];
_registrationOptions = @{kGGLInstanceIDRegisterAPNSOption:deviceToken,
kGGLInstanceIDAPNSServerTypeSandboxOption:@YES};
[[GGLInstanceID sharedInstance] tokenWithAuthorizedEntity:_gcmSenderID
scope:kGGLInstanceIDScopeGCM
options:_registrationOptions
handler:_registrationHandler];
NSLog(@"This is device token%@", deviceToken);
}
这是我发送的推送通知:
curl --header 'Content-Type:application/json' --header 'Authorization: key=My-Google-Key' \
https://android.googleapis.com/gcm/send \
-d '{"to": "/topics/test","notification":{"sound": "default","badge": "1","title": "test title","body": "Test body", "dl": "myscheme://section/e5c7f33080940a95b94b50941e667da6", "content_available":true}, "data":{"alert":"breaking title","title":"breaking title","dl": "myscheme://section/e5c7f33080940a95b94b50941e667da6"", "content_available":true}}'
总结一下,如果应用程序根本没有运行,我还需要一种方法来接收推送通知
答案 0 :(得分:1)
我找到了解决方案,我会留在这里以防其他人遇到同样的问题:
所有关于"优先级"密钥有效载荷
"优先级":10 表示优先级:高,
curl --header 'Content-Type:application/json' --header 'Authorization: key=My-Google-Key' \
https://android.googleapis.com/gcm/send \
-d '{"to": "/topics/test","priority":10,"notification":{"sound": "default","badge": "1","title": "test title","body": "Test body", "dl": "myscheme://section/e5c7f33080940a95b94b50941e667da6"}, "data":{"alert":"breaking title","title":"breaking title","dl": "myscheme://section/e5c7f33080940a95b94b50941e667da6"}}'
参考:https://developers.google.com/cloud-messaging/http-server-ref#priority
旁注:您不必复制"通知"和"数据"这只是一个例子,它不是我在我的应用中使用的真实有效负载。