2011-12-07 1 views
0

나는 아래에 보여입니다 난 내 class.m 파일에 로컬 알림을 설정하는 응용 프로그램이 있습니다 -왜 지역 기록 통지 방법이 작동하지 않았습니까?

-(IBAction)save{ 
NSString *str1=[NSString stringWithFormat:@"%@",txt_date.text]; 
NSString *str2=[NSString stringWithFormat:@" %@",txt_time.text]; 
str1=[str1 stringByAppendingFormat:str2]; 
selected_label.text= str1; 
[[UIApplication sharedApplication] cancelAllLocalNotifications]; 
NSDate *today=[NSDate date]; 
NSDateFormatter* formatter_current = [[[NSDateFormatter alloc] init] autorelease]; 
formatter_current.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"]; 
//Set the required date format 
[formatter_current setDateFormat:@"yyyy-MM-dd hh:mm a"]; 

NSLog(@"current date is =%@",str1); 
today=[formatter_current dateFromString:str1]; 
NSLog(@"current date:-%@",today); 
UILocalNotification* ln = [[UILocalNotification alloc] init]; 
//ln.alertBody = @"Wake Up Sid"; 
//ln.applicationIconBadgeNumber = 1; 
ln.fireDate = today; //[NSDate dateWithTimeIntervalSinceNow:15]; 
ln.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"]; 
NSLog(@"alarm will activate on%@",today); 
NSDateFormatter* formatter_alarm = [[[NSDateFormatter alloc] init] autorelease]; 
NSLocale *uslocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]; 
[formatter_alarm setLocale:uslocale]; 
[uslocale release]; 
formatter_alarm.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"]; 
[formatter_alarm setDateFormat:@"hh:mm a"]; 
NSString *str=[formatter_alarm stringFromDate:today]; 
NSLog(@"%@",str); 
//ln.alertBody = [NSString stringWithFormat:@"Your first appointment at %@",str]; 
//ln.soundName = UILocalNotificationDefaultSoundName; 
ln.repeatInterval=NSDayCalendarUnit; 
[[UIApplication sharedApplication] scheduleLocalNotification:ln]; 
[ln release]; 

}

를하고 난 내 AppDelegate에 파일에 코드를 사용 즉 : -

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ 
// Override point for customization after application launch. 


self.viewController=[[demo_social_updatesViewController alloc]initWithNibName:@"demo_social_updatesViewController" bundle:nil]; 
nav_controller=[[UINavigationController alloc] initWithRootViewController:self.viewController]; 
// Add the view controller's view to the window and display. 
[self.window addSubview:nav_controller.view]; 
[self.window makeKeyAndVisible]; 
appDelegate_acess_token=[[NSUserDefaults standardUserDefaults] stringForKey:@"access_token"]; 
    application.applicationIconBadgeNumber = 0; 
// Handle launching from a notification 
UILocalNotification *localNotif = 
[launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey]; 
if (localNotif) { 
    NSLog(@"Recieved Notification %@",localNotif); 
} 
return YES;} 

- (무효) 응용 프로그램 : (UIApplication *) 응용 프로그램의 didReceiveLocalNotification : (UILocalNotification *) 통지 {

 NSLog(@"Recieved Notification %@",notification); 

이제 알림이 생성되고 didReceiveLocalNotification이 호출되지 않으면 오류가 발생합니다. 이 오류를 어떻게 수정합니까? 발전에

감사 ...

+0

이 방법은 응용 프로그램이 포 그라운드 일 때 작동합니다. – Leena

+0

@iPhone 개발자 어떻게 향상시킬 수 있습니까? – ios

+0

알림이 발생하지만이 메소드가 호출되지 않는다고 말하면 앱이 백그라운드 일 때 어떤 메소드도 호출 할 수 없습니다. – Leena

답변

2
  • (공극) 애플리케이션 (UIApplication *) 애플리케이션 didReceiveLocalNotification (UILocalNotification *) 통지; 닫기 버튼이 아닌 로컬 알림의보기 버튼을 탭하면 함수가 호출됩니다.