gpt4 book ai didi

ios - 本地通知不触发后台获取

转载 作者:行者123 更新时间:2023-11-28 18:53:58 25 4
gpt4 key购买 nike

有人可以看看下面的代码并告诉我为什么本地通知没有触发吗?我在 XCode 中运行应用程序并使用调试选项模拟后台获取,但本地通知不会触发。

- (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
NSLog(@"performFetchWithCompletionHandler");


UILocalNotification *localNotif = [[UILocalNotification alloc] init];

if (localNotif) {
localNotif.alertBody = @"Update demo text!";
localNotif.alertAction = @"OK";
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.fireDate = nil;

NSLog(@"Local Notification");

[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
}

//Perform some operation
completionHandler(UIBackgroundFetchResultNewData);
}

最佳答案

是否查询用户是否允许推送?

if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0) {
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound categories:nil];
[application registerUserNotificationSettings:settings];
}

关于ios - 本地通知不触发后台获取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36356310/

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