我正尝试在Objective-C中为iOS设置一个动态CKNotification,但它无法注册通知。
下面是我的代码:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"notify == %@",userentry2.text];
CKSubscription *newRecordSub = [[CKSubscription alloc] initWithRecordType:savefolder predicate:predicate options: CKSubscriptionOptionsFiresOnRecordUpdate | CKSubscriptionOptionsFiresOnRecordCreation];
CKNotificationInfo *noteInfo = [CKNotificationInfo new];
noteInfo.alertBody=@"%@";
noteInfo.alertLocalizationArgs = [NSArray arrayWithObject:@"message"];
noteInfo.shouldBadge = NO;
noteInfo.soundName = UILocalNotificationDefaultSoundName;
newRecordSub.notificationInfo = noteInfo;
CKContainer *container = [CKContainer defaultContainer];
CKDatabase *publicDatabase = [container publicCloudDatabase];
[publicDatabase saveSubscription:newRecordSub completionHandler:^(CKSubscription *subscription, NSError *error) {
if(error){
NSLog(@"didn't register new notif");
}
else{
NSLog(@"registered new notif");
}
}];以前我只有警报体,没有alertLocalizationArgs,它可以很好地注册,但现在我添加了alertLocalizationArgs功能,它就不会注册了。
有什么想法吗?
发布于 2016-08-22 04:26:22
您可以使用alertBody,也可以使用alertLocalizationKey和alertLocalizationArgs。你不能把这两者混为一谈。
不清楚你想要的信息是什么。分配@[ @"message" ]在任何情况下都没有意义。
也可以这样做:
noteInfo.alertBody = @"Some message you create";或执行以下操作:
noteInfo.alertLocalizationKey = @"Some Key in your Localized.strings file";
noteInfo.alertLocalizationArgs = @[ @"argument value 1", @"argument value 2" ];其中本地化参数是被替换的值,就像在与本地化关键字关联的任何值中使用stringWithFormat:一样。只有当本地化后的值具有1个或更多参数时,才使用args。
https://stackoverflow.com/questions/39067636
复制相似问题