【发布时间】:2015-01-15 14:12:19
【问题描述】:
我正在构建一个应用程序,该应用程序将实现 Parse 后端以发送推送通知。用户将能够向其他用户发送包含在推送通知中的消息。我一直在玩这个,当我发送它时在 Parse 网站上注册很好,但只有大约 50% 的发送消息在设备上被接收。还有其他人有这个问题吗?我知道推送通知不能保证但有 50% 的成功率?有任何想法吗?
谢谢
代码如下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[Parse setApplicationId:@"***"
clientKey:@"****"];
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
return YES;
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
// Store the deviceToken in the current installation and save it to Parse.
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation setDeviceTokenFromData:deviceToken];
currentInstallation.channels = @[ @"global" ];
[currentInstallation saveInBackground];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
[PFPush handlePush:userInfo];
}
- (void)notifyFriendAtIndex:(NSInteger)index completionHandler:(userCompletionHandler)handler
{
PFQuery *pushQuery = [PFInstallation query];
[pushQuery whereKey:@"deviceType" equalTo:@"ios"];
NSString *pushMessage = [NSString stringWithFormat:@"From %@ HI!", self.currentUser.username];
NSDictionary *pushData = @{@"alert": pushMessage, @"badge": @0, @"sound": @"notify.wav"};
PFPush *push = [[PFPush alloc] init];
[push setQuery:pushQuery];
[push setData:pushData];
[push sendPushInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error) {
NSLog(@"Error: %@ %@", error, [error userInfo]);
handler(NO, error);
}
else {
handler(YES, nil);
}
}];
}
【问题讨论】:
-
这听起来像是一个用户端问题,到目前为止,parse.com 已被证明忠于它的基础。显示一些有关如何发送它们的相关代码。你在定义渠道、用户等吗?
-
在上面添加了我的代码、AppDelegate 方法和我的 notify 方法。现在用户可以向所有 iOS 设备发送推送(仅用于测试目的)。看起来还好吗?
-
看起来不错。再说一次,并不是说它们是完美的,但出于某种原因,它们是最好的之一,而且它们在过去并没有被证明是不可靠的。如果问题仍然存在,您应该向他们提交票证,以便他们进行调查。但只要仔细看看你的应用程序,此时它仍然感觉像是一个用户端问题。您如何跟踪您的推送成功率?
-
实际上可能已修复它....粘贴代码时,我注意到 userinfo 在新行上,而不是在 (NSDictionary*) 旁边,也许我不小心按了返回。不知道为什么 Xcode 让我编译它……也不知道为什么它会有所作为。反正我已经改正了。只需花 20 分钟测试到目前为止,成功率是 100%!不想肯定地说它已经修复可能只是侥幸,但这是一个巨大的变化。以前从未有过100%。手指交叉......奇怪的错误 -
-
我通过查看 Parse.com 控制面板上的推送部分来跟踪成功率。有人说推送是否传递到设备。到目前为止一切顺利。
标签: ios xcode parse-platform push-notification