다음 코드를 사용하여 현재 로컬 알림 목록을 유지하려고합니다. NSArray는 명시 적으로 작업 할 객체의 종류를 나열합니다. 이는 UILocalNotification 객체로 구성된 배열로 사용할 수 없다는 것을 의미합니다. 그러나 UILocalNotifications는 NSCoding을 구현하므로이 객체 목록을 serialize/deserialize 할 수있는 쉬운 방법이 있어야합니다. 인코딩과 파일 지속성을 직접 수행해야합니까? 또한 쓰기가 실패한 이유에 대한 자세한 정보를 얻을 수있는 방법이 있습니까? 슬래시 (/)를 보장 할 파일 이름 앞에 필요한 경우, 포함되어디스크에 UILocalNotifications의 배열을 쓸 수 있습니까?
- (NSString*)getSavedNotifsPath {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
return [documentsDirectory stringByAppendingString:@"saved_notifs.plist"];
}
- (void)prepareToHide {
UIApplication* app = [UIApplication sharedApplication];
NSArray *existingNotifications = [app scheduledLocalNotifications];
if (! [existingNotifications writeToFile:[self getSavedNotifsPath] atomically:NO]) {
// alert
[self showSomething:@"write failed"];
}
}
쿨, 고마워 커비! 나는 NSKeyedArchiver가 존재하는지 몰랐다. NSKeyedUnarchiver와 쌍을 이루면 효과가 있습니다. 감사! –