2

私はローカル通知に取り組んでおり、各通知を識別するために、Core Data モデルからその辞書のキーとしてNSDictionaryを取得する必要があります。ManagedObjectID

問題は、これを行うと次のエラーが発生することです。

Property list invalid for format: 200 (property list dictionaries may only have keys which are CFStrings, not 'CFType')

これは、辞書が特定のデータ型のみを格納でき、NSManagedObjectID を格納できないという事実に関係しています。

私の質問は、これNSManagedObjectIdNSStringorに変換する方法はありますかNSNumber。その特定の通知を削除するために後で識別するために、その特定のIDが本当に必要です。

これまでのコード:

    -(void) scheduleNotificationAtDate:(NSDate*)date WithBody:(NSString*) body WithBillEventId:(NSManagedObjectID*) billEventId{

// Schedule the notification
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = date;
localNotification.alertBody = body;
localNotification.alertAction = @"Ga naar de Rekening Delen app";
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;

//set the dictionary here,
NSDictionary *billEventIdentifier = [NSDictionary dictionaryWithObject:@"billevent_notification" forKey: billEventId];
localNotification.userInfo = billEventIdentifier;
NSLog(@"set local notification");
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}
4

1 に答える 1

2

あなたが抱えている問題は、オブジェクトがディクショナリに適切に保存され、ディスクにシリアル化されるためには、NSManagedObjectID が準拠していない NSCoding に準拠している必要があることです。

幸いなことに、別の方法があります。URIRepresentationCore Data オブジェクトの識別子となるNSManagedObjectID に呼び出されるメソッドがあり、NSManagedObjectIDを格納する代わりにそれを使用できます。次に、次の例のように、その NSURL URIRepresentation を NSManagedObjectID に戻すことができます。

NSManagedObjectID *objectID = [context.persistentStoreCoordinator managedObjectIDForURIRepresentation:myObjectURI];
于 2014-05-14T14:54:20.607 に答える