//如果没有开启通知提示打开通知
if (IOS_VERSION >= 10.0) {
[[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
dispatch_sync(dispatch_get_main_queue(), ^{
if (settings.authorizationStatus == UNAuthorizationStatusDenied) {
[self showHeadView];
}else if (settings.authorizationStatus == UNAuthorizationStatusNotDetermined) {
[self showHeadView];
}else if (settings.authorizationStatus == UNAuthorizationStatusAuthorized) {
}
});
}];
}
else if (IOS_VERSION >= 8.0)
{
// UIUserNotificationSettings *setting = [[UIApplication sharedApplication] currentUserNotificationSettings];
// if (UIUserNotificationTypeNone != setting.types) {
// [self showHeadView];
// }else {
//
// }
bool result = [[UIApplication sharedApplication] isRegisteredForRemoteNotifications];
if (!result) {
[self showHeadView];
}
}
有一个需求,如果用户没有打开通知权限,需要调用[self showHeadView];
在tableView
的顶部显示一个提示控件,正常如图:
但是遇到一个问题,按钮的title不显示,要点一下,或等一会儿才能显示:
后来发现是之前的写法导致[self showHeadView];
在子线程调用,子线程操作UI导致的,子线程进行的UI操作也会保留,但是要到子线程销毁的时候才会在主线程进行显示,所以有时过一会儿会显示。
正确写法见顶部,会主线程执行UI操作