不推荐使用UIRemoteNotificationTypeAlert - 如何与大型团队一起过渡到UIUserNotificationTypeAlert?

nor*_*000 8 deprecated apple-push-notifications ios

我想快速转换出已弃用的推送通知常量,但顺利.我知道实现远程和本地通知的方法也发生了变化,但这超出了本问题的范围.

以下是应考虑的一些因素/约束:

  1. 我有一个相当庞大的iOS开发团队.
  2. 一些开发人员仍在使用xCode 5,它不能使用iOS 8 API进行编译.
  3. 一些开发人员已经在使用xCode 6.2 Beta 3,它使用了xCode 6.1.1中没有的额外WatchKit目标.
  4. 绝大多数开发人员都在使用xCode 6.1.1.

谢谢您的帮助!

She*_*mus 11

幸运的是,这是相当直接的.您需要做的就是使用编译器指令,最好是在推送通知中心的头文件中.在条件指令中,您可以使用定义将自己的常量集映射到新集或不建议集,具体取决于xCode支持的最新iOS版本.

#ifdef __IPHONE_8_0
    #define RemoteNotificationTypeAlert UIUserNotificationTypeAlert
    #define RemoteNotificationTypeBadge UIUserNotificationTypeBadge
    #define RemoteNotificationTypeSound UIUserNotificationTypeSound
    #define RemoteNotificationTypeNone  UIUserNotificationTypeNone
#else
    #define RemoteNotificationTypeAlert UIRemoteNotificationTypeAlert
    #define RemoteNotificationTypeBadge UIRemoteNotificationTypeBadge
    #define RemoteNotificationTypeSound UIRemoteNotificationTypeSound
    #define RemoteNotificationTypeNone  UIRemoteNotificationTypeNone
#endif
Run Code Online (Sandbox Code Playgroud)