ios 编译版本 最低版本 运行版本 动态链接库

本文介绍了如何在iOS不同版本中正确申请远程通知权限的方法。包括针对iOS 10及更高版本使用UNUserNotificationCenter进行授权请求,对于iOS 8到9的设备采用UIUserNotificationSettings设置,以及更早版本系统的远程通知类型注册。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) 运行环境判断;

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 编译器、开发环境支持;

部署环境支持;

 

UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]

在低于库版本的运行环境运行时,center返回值为nil;

 

结论:

1)在对象或类符号不存在时,动态库没有任何存在,返回值为nil;

2)当一个类的接口存在跨系统级别的函数存在时,因为类或对象存在,函数符号不存在,所以存在崩溃的情况。

 

 

- (void)registerRemoteNotification {

    if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 // Xcode 8编译会调用

        UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];

        center.delegate = self;

        [center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionCarPlay) completionHandler:^(BOOL granted, NSError *_Nullable error) {

            if (!error) {

                NSLog(@"request authorization succeeded!");

            }

        }];

        

        [[UIApplication sharedApplication] registerForRemoteNotifications];

#endif

    } else if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {

        UIUserNotificationType types = (UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge);

        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil];

        [[UIApplication sharedApplication] registerUserNotificationSettings:settings];

        [[UIApplication sharedApplication] registerForRemoteNotifications];

    } else {

        UIRemoteNotificationType apn_type = (UIRemoteNotificationType)(UIRemoteNotificationTypeAlert |

                                                                       UIRemoteNotificationTypeSound |

                                                                       UIRemoteNotificationTypeBadge);

        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:apn_type];

    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值