1

我编写了以下代码来显示本地通知。但是,当我收到通知时,通知上没有显示按钮。有人可以告诉我我做错了什么吗?我在应用程序中编写了以下代码确实进入了后台事件。

UILocalNotification *local=[[UILocalNotification alloc]init];
    NSDate *alertTime = [[NSDate date] dateByAddingTimeInterval:10];
    local.fireDate=alertTime;
    local.timeZone=[NSTimeZone defaultTimeZone];
    local.alertBody=@"Hello this is a local notif";
    local.alertAction=@"Show";
    local.repeatInterval=0;
    local.applicationIconBadgeNumber=1;
    local.soundName=UILocalNotificationDefaultSoundName;

    UIApplication *abc=[UIApplication sharedApplication];
    [abc scheduleLocalNotification:local];
4

1 回答 1

0

您必须使用以下方法在 AppDelegate.m 文件中编写代码。

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{

    if (application.applicationState == UIApplicationStateActive) {

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:notification.alertBody delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Show", nil];
        [alert show];
                [alert release];
    }
}
于 2012-12-11T08:52:29.697 回答