2011-01-13 21 views
1

我試圖做UILocalNotification USERINFO不序列化NSURL

UILocalNotification *notification = [[UILocalNotification alloc] init]; 
NSURL *urlForSomeObject=[[(NSManagedObject *)someObject objectID] URIRepresentation]; 
notification.fireDate = aDate; 
notification.timeZone = [NSTimeZone systemTimeZone]; 
notification.soundName = UILocalNotificationDefaultSoundName; 
notification.applicationIconBadgeNumber = 1; 
notification.userInfo=[NSDictionary dictionaryWithObject:urlForSomeObject   forKey:@"objectUrl"]; 

時通知出現應用程序使異常 unable to serialize userInfo: (null)' 我已經檢查了[NSDictionary的dictionaryWithObject:urlForSomeObject forKey:@ 「的ObjectURL」]返回一個有效的字典。 爲什麼會發生這種行爲。據我所知NSURL堅持NSCoding協議,應該序列化。 有人可以幫我嗎?

回答

6

UILocalNotification上的userInfo字典必須僅包含「plist類型」。 NSURL不是plist類型。我建議將字符串序列化爲字典中的字符串,然後在收到通知時將其轉換回NSURL。