2011-08-01 96 views
0

我在我的应用程序中使用提醒的本地通知。我需要使用名称设置任何闹钟,以便仅针对每项活动发出警报。我会使用NSUserDefaults来获得键值。现在我使用这个系统,不允许我这样做。NSUserDefaults +本地通知

-(void)scheduleAlarm:(id)sender { 

NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar]; 

// Get the current date 
NSDate *pickerDate = [datePicker date]; 

// Break the date up into components 
NSDateComponents *dateComponents = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) 
               fromDate:pickerDate]; 
NSDateComponents *timeComponents = [calendar components:(NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit) 
               fromDate:pickerDate]; 

// Set up the fire time 
NSDateComponents *dateComps = [[NSDateComponents alloc] init]; 
[dateComps setDay:[dateComponents day]]; 
[dateComps setMonth:[dateComponents month]]; 
[dateComps setYear:[dateComponents year]]; 
[dateComps setHour:[timeComponents hour]]; 
// Notification will fire in one minute 
[dateComps setMinute:[timeComponents minute]]; 
[dateComps setSecond:[timeComponents second]]; 
NSDate *itemDate = [calendar dateFromComponents:dateComps]; 
[dateComps release]; 

UILocalNotification *localNotif = [[UILocalNotification alloc] init]; 
if (localNotif == nil) 
    return; 
localNotif.fireDate = itemDate; 
localNotif.timeZone = [NSTimeZone defaultTimeZone]; 

// Notification details 
localNotif.alertBody = [mainTitle text]; 
// Set the action button 
localNotif.alertAction = @"View"; 

localNotif.soundName = UILocalNotificationDefaultSoundName; 

// Specify custom data for the notification 
NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"someValue" forKey:@"someKey"]; 
localNotif.userInfo = infoDict; 

// Schedule the notification 
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif]; 
[localNotif release]; 





} 

非常感谢!

回答

0

拥有NSUserDefaults的此实例方法:

- (NSDictionary *)dictionaryForKey:(NSString *)defaultName 

为什么不能用它来返回您需要为您的本地通知的userInfo属性字典?

+0

好的非常感谢 – Vins