2011-10-27 35 views
0

我正在嘗試將NSManagedObjectID附加到UILocalNotification但仍然收到錯誤: 屬性列表格式無效:200(屬性列表不能包含'CFType'類型的對象)在UILocalNotification中設置UserInfo時出錯

這是我的代碼(taskID是NSManagedObjectID ):

// Create the new notification 
UILocalNotification *newNotice = [[notificationClass alloc] init]; 
[newNotice setFireDate:date]; 
[newNotice setTimeZone:[NSTimeZone defaultTimeZone]]; 
[newNotice setAlertBody:@"Test text"]; 

// Add the object ID to the userinfo 
NSDictionary *myUserInfo = [NSDictionary dictionaryWithObject:taskID forKey:@"TaskID"]; 
newNotice.userInfo = myUserInfo; 

taskID通過此代碼傳遞到函數中(第一個參數):

addNotification([task objectID], [task taskname], [task taskexpiry]); 

任務是一個NSManagedObject,該代碼已經過測試並且工作正常了很長時間。

從我讀過的一切都應該可行。任何幫助將不勝感激。

Jason

+0

發佈定義和實例化taskID的代碼,機會就在於問題所在。 – Jim

+0

在發佈taskID的帖子中增加了一些信息。 – Jason

回答

13

userInfo必須是有效的屬性列表。見What is a Property List?NSManagedObjectID不是屬性列表中允許的任何類型。

嘗試使用[[taskID URIRepresentation] absoluteString]作爲您的userInfo。您稍後必須使用-[NSPersistentStoreCoordinator managedObjectIDForURIRepresentation:]才能將其重新設爲NSManagedObjectID

+0

太棒了,做到了!感謝Rob。 – Jason

相關問題