2016-08-21 37 views
0

我正在嘗試爲Objective-C中的iOS設置動態CKNotification,但它無法註冊通知。我的動態CKNotification將不會註冊

這裏是我的代碼:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"notify == %@",userentry2.text]; 
CKSubscription *newRecordSub = [[CKSubscription alloc] initWithRecordType:savefolder predicate:predicate options: CKSubscriptionOptionsFiresOnRecordUpdate | CKSubscriptionOptionsFiresOnRecordCreation]; 
CKNotificationInfo *noteInfo = [CKNotificationInfo new]; 
[email protected]"%@"; 
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功能,它不會註冊。

任何想法?

回答

0

您可以使用alertBody或使用alertLocalizationKeyalertLocalizationArgs。你不要混淆兩者。

目前還不清楚你想要的信息是什麼。在任何情況下分配@[ @"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個或更多參數時才使用參數。

+0

非常感謝,抱歉,我應該指定:「消息」將是ckrecord中的關鍵字段或字段。 –