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

时间:2015-01-21 01:25:54

标签: javascript ios objective-c parse-platform push-notification

好吧所以我使用了parse.com功能来处理很多事情,例如为用户存储信息......

我决定使用parse.com推送服务,到目前为止我对结果并不满意。设置起来非常简单,但是我发送的推送并不总是被发送"。

有其他人遇到这个问题并解决了吗?

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

enter image description here

这些都是我在应用程序运行时尝试的示例。有时它工作有时它没有你看到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 &#34;推送&#34;代码

我真的不认为推送代码是怎样的,因为我试图以这两种方式测试...

1)https://www.parse.com/apps/quickstart?app_id=pickmeup--15#parse_push/ios/existing 我使用这个代码来解析自己的代码来发送推送通知,这里有时它来了,有时也没有..

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

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

Cloud Code

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

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

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

0 个答案:

没有答案