2011-08-01 9 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

okありがとう – Vins

関連する問題