Iphone 本地通知在ios中无法正常工作
我有一个应用程序,如果用户有一段时间没有打开该应用程序,我将使用本地通知 如果用户通过本地通知打开应用程序,我的数据库将更新,并向用户的帐户提供积分,我将显示警报“您已获得额外积分” 当用户单击“确定”时,“我的数据库”中的积分会更新,但“我的viewcontroller”不会得到刷新,并且此时它不会在标签上显示更新的积分 当我走到另一个视图回来时,它显示出来了 当用户从AlertView单击OK时,我应该如何获得更新的分数 提前谢谢 编辑Iphone 本地通知在ios中无法正常工作,iphone,ios,objective-c,uilocalnotification,Iphone,Ios,Objective C,Uilocalnotification,我有一个应用程序,如果用户有一段时间没有打开该应用程序,我将使用本地通知 如果用户通过本地通知打开应用程序,我的数据库将更新,并向用户的帐户提供积分,我将显示警报“您已获得额外积分” 当用户单击“确定”时,“我的数据库”中的积分会更新,但“我的viewcontroller”不会得到刷新,并且此时它不会在标签上显示更新的积分 当我走到另一个视图回来时,它显示出来了 当用户从AlertView单击OK时,我应该如何获得更新的分数 提前谢谢 编辑 [[UIApplication sharedAppli
[[UIApplication sharedApplication]cancelAllLocalNotifications];
NSDate *today=[NSDate date];
NSLog(@"%@",today);
NSDateFormatter *dateFormat1 = [[NSDateFormatter alloc] init];
[dateFormat1 setDateFormat:@"dd-MMM-yyyy hh:mm:ss a"];
NSTimeInterval secondsInEightHours = 20;
NSString *tt=[dateFormat1 stringFromDate:today];
//tt=@"20-Apr-2013 06:39:32 PM";
NSDate *Ass_date=[dateFormat1 dateFromString:tt];
Ass_date=[Ass_date dateByAddingTimeInterval:secondsInEightHours];
NSLog(@"%@",tt);
NSLog(@"%@",today);
NSLog(@"%@",Ass_date);
//[[UIApplication sharedApplication]cancelAllLocalNotifications];
UILocalNotification *localNotif1 = [[UILocalNotification alloc] init];
[[UIApplication sharedApplication]cancelLocalNotification:localNotif1];
if (localNotif1 == nil)
return;
localNotif1.fireDate = Ass_date;
localNotif1.timeZone = [NSTimeZone defaultTimeZone];
// Notification details
localNotif1.alertBody = @"You have not played for a long time. Play and get 250 Stars credits for free!";
// Set the action button
localNotif1.alertAction = @"Get It Now";
localNotif1.soundName = UILocalNotificationDefaultSoundName;
//localNotif.applicationIconBadgeNumber = 1;
//localNotif1.applicationIconBadgeNumber ++;
// Schedule the notification
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif1];
[localNotif1 release];
这是我在viewcontroller的ViewDidDisplay上执行的代码
现在应用程序中的应用程序内委托收到了本地通知:我显示了一个警报
[self localNotif];
////NSLog(@"Recieved Notification %@",localNotif);
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"250 Stars have been credited to your account" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
单击警报中的“确定”按钮,我希望我的视图控制器得到刷新或重新加载 从您更新信用卡的任何地方发送
NSNotification
(与本地通知不同)。让您的UIViewController
注册该通知,并更新其显示
要发布的标准通知示例:
[[NSNotificationCenter defaultCenter] postNotificationName:@"MyAppCreditsUpdatedNotification" object:nil];
要接收(在视图控制器中),请执行以下操作:
别忘了把这个放在你的dealloc中:
[[NSNotificationCenter defaultCenter] removeObserver:self];
从您更新信用卡的任何地方发送
NSNotification
(与本地通知不同)。让您的UIViewController
注册该通知,并更新其显示
要发布的标准通知示例:
[[NSNotificationCenter defaultCenter] postNotificationName:@"MyAppCreditsUpdatedNotification" object:nil];
要接收(在视图控制器中),请执行以下操作:
别忘了把这个放在你的dealloc中:
[[NSNotificationCenter defaultCenter] removeObserver:self];
问题是您正在更新数据库,而不是
viewContoller
您只需刷新或重新加载viewController
试试这个,这个可能对你有帮助
[self.view setNeedsDisplay];
否则
单击“确定”按钮时,您可以手动更改标签
值,而不是重新加载完整的视图控制器
问题是您正在更新数据库,而不是
viewContoller
您只需刷新或重新加载viewController
试试这个,这个可能对你有帮助
[self.view setNeedsDisplay];
否则
单击“确定”按钮时,您可以手动更改标签
值,而不是重新加载完整的视图控制器
在您的
AppDelegate
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
[[NSNotificationCenter defaultCenter] postNotificationName:@"creditsUpdated" object:nil];
}
在视图控制器中
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateScore:) name:@"creditsUpdated" object:nil];
现在updateScore:
方法将在用户点击本地通知上的“OK”按钮时被调用。您可以在此处更新标签。
希望这能有所帮助。在你
AppDelegate
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
[[NSNotificationCenter defaultCenter] postNotificationName:@"creditsUpdated" object:nil];
}
在视图控制器中
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateScore:) name:@"creditsUpdated" object:nil];
现在updateScore:
方法将在用户点击本地通知上的“OK”按钮时被调用。您可以在此处更新标签。
希望这能有所帮助。你能在这里分享你的代码吗阅读这篇文章,只在关于IDE本身的问题上使用标签。谢谢你能在这里分享你的代码吗阅读这篇文章,对于IDE本身的问题只使用标签。谢谢我已经试过了,但对我无效。我还可以尝试解决什么问题?显示您的代码。您在问题中编辑的示例没有发布通知。正如我所说的,NSNotification与本地通知不同。我已经尝试过了,但没有成功。我还可以尝试解决什么问题?显示您的代码。您在问题中编辑的示例没有发布通知。正如我所说,NSNotification与本地通知不同。是的,您是对的,我需要参考我的ViewController,但上面这一行对我不起作用。我还可以尝试什么?是的,你是对的,我需要参考我的ViewController,但上面这行对我不起作用。我还能试什么?