本地通知从手机的状态栏中消失。如何让它留在那里直到有人访问它

时间:2011-12-14 09:04:48

标签: iphone notifications

我有以下代码,它会创建一个显示在手机状态栏中的本地通知。即使我不访问,通知也会在一段时间后消失。

UILocalNotification *localNotification = [[[UILocalNotification alloc] init] autorelease];

if (!localNotification) 
    return;

// Current date
NSDate *date = [NSDate date]; 

// Add one minute to the current time
NSDate *dateToFire = [date dateByAddingTimeInterval:60];

// Set the fire date/time
[localNotification setFireDate:dateToFire];
[localNotification setTimeZone:[NSTimeZone defaultTimeZone]];
localNotification.repeatInterval = 0;

// Create a payload to go along with the notification
NSArray *array = [NSArray arrayWithObjects:@"Value 1", @"Value 2", nil];
NSDictionary *data = [NSDictionary dictionaryWithObject:array forKey:@"payload"];
[localNotification setUserInfo:data];


// Setup alert notification
[localNotification setAlertBody:@"Incoming notification"];
[localNotification setAlertAction:@"Open App"];
[localNotification setHasAction:YES];    

// Schedule the notification        
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

有人可以帮我创建一个留在状态栏中的通知,直到用户访问它为止? 谢谢

1 个答案:

答案 0 :(得分:2)

没有办法做到这一点,iOS SDK没有提供任何方式使通知保留在状态栏中,直到用户解雇它。