2012-12-11 47 views
1

我已經編寫了下面的代碼來顯示本地通知。但是,當我收到它們時,按鈕沒有顯示在通知上。可以有人告訴我我做錯了什麼? 我在應用程序中編寫了如下一段代碼,並輸入了後臺事件。按鈕不在nslocalnotification中顯示?

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

    UIApplication *abc=[UIApplication sharedApplication]; 
    [abc scheduleLocalNotification:local]; 
+0

你寫過 - (空)應用程序:(UIApplication的*)應用 didReceiveLocalNotification:(UILocalNotification *)在您的應用程序委託類通知功能? –

+0

wt是你的問題.. ??沒有收到通知或證件號碼不顯示???? – 2012-12-11 08:59:19

回答

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