在iOS12这样设置会闪退
UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
[content setValue:@(YES) forKeyPath:@"shouldAlwaysAlertWhileAppIsForeground"];
这样做的目的通常是为了在前台收到推送通知, 或者本地通知时也显示弹窗, 所以可以修改以下方法设置
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler API_AVAILABLE(ios(10.0)){
........
//当应用处于前台时提示设置,需要哪个可以设置哪一个
if (@available(iOS 10.0, *)) {
completionHandler(UNNotificationPresentationOptionSound|UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionAlert);
} else {
// Fallback on earlier versions
}
}
另外如果你是iOS12的系统, 在前台收到推送后没有走这个方法, 检查
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if (@available(iOS 10.0, *)) {
[UNUserNotificationCenter currentNotificationCenter].delegate=self; // 检查这个代理是否设置
}
}
最后
以上就是冷傲秋天最近收集整理的关于iOS12 shouldAlwaysAlertWhileAppIsForeground闪退的全部内容,更多相关iOS12内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复