简体   繁体   中英

Button not showing in nslocalnotification?

I have written the following code for displaying local notifications.However,a button is not showing up on the notifications when i receive them.Can anybody tell me what I am doing wrong? I have written the following piece of code in application did enter background event.

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];

You have to write your code in AppDelegate.m File in below method.

- (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];
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM