Ios 前台弹出通知
我想在应用程序处于前台状态时显示通知弹出窗口,根据代码片段显示alertbodyIos 前台弹出通知,ios,iphone,uilocalnotification,Ios,Iphone,Uilocalnotification,我想在应用程序处于前台状态时显示通知弹出窗口,根据代码片段显示alertbody 当应用程序处于后台状态时,它完全可以工作 UILocalNotification *notification = [[UILocalNotification alloc] init]; if (notification == nil) return; NSDate *dt = [NSDate dateWithTimeInterval:10 sinceDate:[NSDate date]]; notifica
当应用程序处于后台状态时,它完全可以工作
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];
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];
}
}
我假设您知道,当应用程序处于前台状态时,会在ApplicationIDReceiveLocalNotification方法中收到通知(但不确定方法的名称),如果您希望显示类似于横幅的通知,可以从中显示警报。