我想在应用处于前台状态时显示通知弹出窗口,并根据代码片段显示alertbody。
当应用处于后台状态时,它完全正常工作。
UILocalNotification *notification = [[UILocalNotification alloc] init];
if (notification == nil)
return;
NSDate *dt = [NSDate dateWithTimeInterval:10 sinceDate:[NSDate date]];
notification.fireDate = dt;
notification.timeZone = [NSTimeZone defaultTimeZone];
notification.alertBody = @"After 10Secs...";
notification.alertAction = @"View";
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
答案 0 :(得分:1)
application:didreceiveLocalNotification
您的应用委托方法:
- (void)application:(UIApplication *)application
didReceiveLocalNotification:(UILocalNotification *)notification
{
//simply show a alert,but the standard one will not show up by itself
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"MyAlertView"
message:notification.alertBody
delegate:self cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
if (alertView) {
[alertView release];
}
}