0

看起来Apple已经具有内置功能来通过在aps有效载荷中包含loc-key来本地化PUSH通知。但是,我不相信Parse的iOS SDK允许您使用sendPushInBackground自己设置该密钥。有没有什么办法可以使用Parse本地化PUSH而无需首先路由到我自己的服务器?如何本地化分析推送通知?

回答

0

与PFPush一起使用的数据字典中的警报密钥可以设置为字典而不是字符串。

任何人谁在将来发现这一点,我的是这样的:

NSDictionary *data = [NSDictionary dictionaryWithObjectsAndKeys: 
         @{@"loc-key":@"NEW_MESSAGE_PUSH", @"loc-args":@[sender.name]}, @"alert", 
         @"default", @"sound", 
         @"Increment", @"badge", 
         sender.pid, @"senderID", 
         nil]; 
2
PFQuery *pushQuery = [PFInstallation query]; 
[pushQuery whereKey:@"user" equalTo:author]; 
NSString *key = @"PUSH_LOC_KEY_SEND_TO_AUTHOR"; 
NSArray *args = @[name] 
NSDictionary *data = @{ 
         @"alert": @{@"loc-key": key, 
             @"loc-args": args}, 
          @"badge": @"Increment", 
          @"sound": @"default" 
          }; 
PFPush *push = [[PFPush alloc] init]; 
[push setQuery:pushQuery]; 
[push setData:data]; 

然后在Localizable.strings(基地)地址:

"PUSH_LOC_KEY_SEND_TO_AUTHOR" = "%@ sent you a message"; 

在Localizable.strings(法文)add:

"PUSH_LOC_KEY_SEND_TO_AUTHOR" = "%@ vous envoyé un message"; 

并且请注意,在用户授权应用后,您应该将当前用户对象添加到安装中,以便我们可以PFQuery他(如上所示):

PFInstallation *installation = [PFInstallation currentInstallation]; 
installation[@"user"] = [PFUser currentUser]; 
[installation saveEventually];