parse.com推送服务真的可靠还是我做错了什么?

好吧所以我使用了parse.comfunction,用于存储用户信息等很多东西……

我决定使用parse.com推送服务,到目前为止我对结果并不满意。 这很容易设置等等,但我发送的推送并不总是被“发送”。

是否有其他人遇到这个问题并解决了它?

问题:我正在运行我的应用程序并按下按钮向自己发送推送通知。 我等了大约30秒然后再次按下按钮。 有时通知到达有时它不会。 这是一张它的样子。

在此处输入图像描述

这些都是我在应用程序运行时尝试的示例。 有时它工作有时它没有你看到1意味着我收到了推动,我看到了警报,0没有发生任何事情。 编辑

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. [Parse setApplicationId:@"" clientKey:@""]; // Register for Push Notitications if ([application respondsToSelector: @selector (registerUserNotificationSettings :)]) { /*UIUserNotificationSettings * settings = [UIUserNotificationSettings settingsForTypes: UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound categories: nil ]; [[UIApplication sharedApplication] registerUserNotificationSettings: settings]; [[UIApplication sharedApplication] registerForRemoteNotifications]; */ // Register for Push Notitications UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound); UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes categories:nil]; [application registerUserNotificationSettings:settings]; [application registerForRemoteNotifications]; } else { //using this code or else it crashes when device is using < IOS 8 [[UIApplication sharedApplication] registerForRemoteNotificationTypes: UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound]; } 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 saveInBackground]; } - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { [[NSNotificationCenter defaultCenter] postNotificationName:@"PushNotificationMessageReceivedNotification" object:nil userInfo:userInfo]; [PFPush handlePush:userInfo]; } 

EDIT2 “推送”代码

我真的认为推送代码看起来并不重要,因为我试图通过几种方式测试它…

1) https://www.parse.com/apps/quickstart?app_id=pickmeup–15#parse_push/ios/existing我使用这段代码解析自己的代码来发送推送通知,有时它也会来,有时候才不是..

2)我使用了parse.com提供的curl推送通知,结果相同。

3)我使用自己的代码,我按下按钮并发送推送通知。 这是代码

云代码

 Parse.Cloud.define("sendPushToDevice", function(request, response) { var message = "Please work!"; var friendChannel = "x" + request.params.number; Parse.Push.send({ channels: [ friendChannel ], data: { alert: message } }, { success: function() { response.success("It worked"); }, error: function(error) { response.error("It failed"); } }); }); 

Objective-C代码

  NSDictionary *params = [NSDictionary dictionaryWithObject:self.textField.text forKey:@"number"]; [PFCloud callFunctionInBackground:@"sendPushToDevice" withParameters:params block:^(id object, NSError *error) { if (!error) { NSLog(@"Success push sent"); } else { NSLog(@"Failed to push"); } }]; 

我总是得到成功的推送……但是如前所述,有时候没有推动……希望你看到一个问题。 注意我试过前景和背景

编辑3

在推送发送的同一个ViewController中,我已将其设置为接收推送通知..也许这是罪魁祸首?

 - (void)viewDidLoad { [super viewDidLoad]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(remoteNotificationReceived:) name:@"PushNotificationMessageReceivedNotification" object:nil]; } - (void)remoteNotificationReceived:(NSNotification *)notification { UIAlertView * alert =[[UIAlertView alloc ] initWithTitle:@"Test" message:@"It worked" delegate:self cancelButtonTitle:@"Decline" otherButtonTitles: nil]; [alert addButtonWithTitle:@"Accept"]; [alert show]; } 

编辑4

好的,所以我尝试再次使用此链接尝试发送推送。 https://www.parse.com/apps/quickstart?app_id=pickmeup–15#parse_push/ios/existing

我还试图通过我自己的解析推送面板发送推送,这次一切似乎都顺利和有效,推送通知每次都到达。

但是现在问题仍然存在,当我使用我自己的代码发送推送时,推送通知有时会到达。

它突然开始工作仍然很奇怪。

所以最后一个问题是我自己发送的推送通知。

EDIT5

在此之前我订阅了一个视图控制器中的通道。 点击下一个按钮后,我检查validation码是否匹配,如果有效,那么在我推送到这个视图控制器之前我保存它。

  NSString *xNumber = [NSString stringWithFormat: @"%@%@", x, number]; PFInstallation *currentInstallation = [PFInstallation currentInstallation]; [currentInstallation addUniqueObject:xNumber forKey:@"channels"]; [currentInstallation saveInBackground];