从iOS withPrameters发送推送NSMutableArray不工作Parse.com

时间:2015-05-22 12:36:43

标签: ios objective-c parse-platform

我试图在调用函数时从我的iOS应用程序发送推送通知(当用户在UITableView中选择收件人并发送照片时)。当我调用该函数时,我在Xcode中收到此错误消息:

[Error]: invalid JSON (Code: 107, Version: 1.7.1)
Error sending push notification: The operation couldn’t be completed. (Parse error 107.)

我有一个名为sentPhoto的Cloud Code功能,如下所示:

// Sent photo
Parse.Cloud.define("sentPhoto", function(request, response) {
  var fromUser = request.user;
  var toUser = new Parse.User;
  toUser.id = request.params.user;

  fromUser.fetch().then(function() {
    if (toUser.id==fromUser.id) {
      //throw "(pokeUser:1) Same ";
      response.error("Same user");
      return;
    }

    var pushQuery = new Parse.Query(Parse.Installation);
    pushQuery.equalTo('deviceType', 'ios');
    pushQuery.equalTo('user', toUser);

    return Parse.Push.send({
      where: pushQuery, // Send to all matching query
      expiration_interval: 3 *24*60*60,
      data: {
        alert: fromUser.get("username").split(" ")[0]+" just sent a photo",
        user:fromUser.id
      }
    });

  }, function(error) {
    //throw "(pokeUser:2) Got an error " + error.code + " : " + error.message;
    response.error("(pokeUser:1) Got an error " + error.code + " : " + error.message);

  }).then(function() {

    // Push was successful
    //throw "(pokeUser:0) S ";
    response.success();

  }, function(error) {
    //throw "(pokeUser:3) Got an error " + error.code + " : " + error.message;
    response.error("(pokeUser:2) Got an error " + error.code + " : " + error.message);
  });

});

这就是iOS代码的样子:

- (IBAction)sendPhoto {

    PFObject *message = [PFObject objectWithClassName:@"Messages"];

    [message setObject:[PFUser currentUser] forKey:@"fromUser"];
    [message setObject:[PFUser currentUser] forKey:@"toUser"];
    [message setObject:@"image" forKey:@"fileType"];

    [message setObject:self.recipients forKey:@"recipientIds"];
    [message setObject:[[PFUser currentUser] objectId] forKey:@"senderId"];

    // Image
    NSData *imageData = UIImageJPEGRepresentation(_Image, 0.1f);
    NSString *filename = [NSString stringWithFormat:@"Image.png"];
    PFFile *imageFile = [PFFile fileWithName:filename data:imageData];
    [message setObject:imageFile forKey:@"file"];

    [message saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        if (!error) {

            // Show success message
            [SVProgressHUD showSuccessWithStatus:@"Sweet, your photo has been sent!"];

            [self reset];

            [PFCloud callFunctionInBackground:@"sentPhoto" withParameters:_recipients block:^(id object, NSError *error) {
                if (error) {
                    NSLog(@"Error sending push notification: %@", error.localizedDescription);
                    return;
                }
                NSLog(@"Push notification sent!");
            }];

        } else {
            [SVProgressHUD showErrorWithStatus:@"Oh darn! Something went wrong :("];
        }
    }];
}

_recipients是一个NSMutableArray,它包含didSelectRowAtIndexPath函数中的所有选定收件人。

0 个答案:

没有答案