gpt4 book ai didi

iphone - UILocalNotification 没有出现在 iOS7 中

转载 作者:搜寻专家 更新时间:2023-10-30 19:49:12 24 4
gpt4 key购买 nike

我在我的项目中使用 UILocalNotification。我的代码:

        UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.fireDate = event.date;
notification.timeZone = [NSTimeZone systemTimeZone];

notification.hasAction = YES;
notification.soundName = UILocalNotificationDefaultSoundName;
[notification setApplicationIconBadgeNumber:[UIApplication sharedApplication].applicationIconBadgeNumber+1];

notification.alertBody = @"test alert body";

notification.repeatInterval = NSDayCalendarUnit;

NSLog(@"SCHEDULED NOTIFICATION = %@", notification);

[[UIApplication sharedApplication] scheduleLocalNotification:notification];

在应该出现通知的时候,什么也没有发生,但应用程序的徽章图标值得到 +1。对于 iOS6,它工作正常。哪里会出问题?

更新 在我的应用程序运行和关闭时,我没有收到任何关于通知的警报。唯一的徽章号码正在改变。

最佳答案

如果您在前台运行它,通常会丢失 didReceiveLocalNotification:

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

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"]
message:notification.alertBody
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];

[alertView show];

// Reset badges if you want
application.applicationIconBadgeNumber = 0;
}

关于iphone - UILocalNotification 没有出现在 iOS7 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19002506/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com