我正在使用重复本地通知向用户显示警报。为此,我使用了以下代码
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = [[NSDate date] dateByAddingTimeInterval:60];
localNotification.alertBody = @"sss";
localNotification.alertAction = @"Show me the item";
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
使用 NSNotification Center 我将每 60 秒调用一次本地通知。它工作正常。
我也在 Appdelegate 中使用以下代码:-
- (void)applicationUIApplication *)application didReceiveLocalNotificationUILocalNotification *)notification
{
NSLog(@"Received");
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateActive) {
[[NSNotificationCenter defaultCenter] postNotificationName"RestartProcess" object:self];
}
application.applicationIconBadgeNumber = 0;
}
还有
- (BOOL)applicationUIApplication *)application didFinishLaunchingWithOptionsNSDictionary *)launchOptions
{
UILocalNotification *locationNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (locationNotification) {
// Set icon badge number to zero
NSLog(@"Yes Notid=fications is predsent");
application.applicationIconBadgeNumber = 0;
}
return YES;
}
我的问题是当本地通知开始时,我按下主页按钮然后等待显示。时间段后显示通知消息。
当我点击应用程序图标时,进程停止。之后本地通知不起作用。但是当我点击通知消息时,它会正常工作。我该如何解决这个问题。任何人都可以帮我做到这一点。提前谢谢..
Best Answer-推荐答案 strong>
didReceiveLocalNotification 仅在您点击通知消息时调用。如果您想在 applicationDidBecomeActive 中执行此操作,则必须手动执行。
您可以检查角标(Badge)数量(如果通知包含角标(Badge)),例如:
-(void) applicationDidBecomeActiveUIApplication *)application
{
if(application.applicationIconBadgeNumber >= 1)
{
//Do you stuff here
application.applicationIconBadgeNumber = 0;
}
}
关于ios - 输入 applicationDidBecomeActive 时本地通知不起作用,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/23333156/
|