2011-12-07 7 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 *)通知。閉じるボタンではなくローカル通知のビューボタンをタップすると関数が呼び出されます。
関連する問題