Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios7 #ifdef_uuiPhone_8_0代码也在iOS 7上运行_Ios7_Apple Push Notifications_Ios8 - Fatal编程技术网

Ios7 #ifdef_uuiPhone_8_0代码也在iOS 7上运行

Ios7 #ifdef_uuiPhone_8_0代码也在iOS 7上运行,ios7,apple-push-notifications,ios8,Ios7,Apple Push Notifications,Ios8,我的应用程序中有以下代码——我在评论中看到了iOS 7上的一些崩溃 + (void)registerDeviceForRemoteNotifications { #if !TARGET_IPHONE_SIMULATOR if ([[KOAAuthenticator sharedAuthenticator] currentUser] != nil) { UIApplication *sharedApplication = [UIApplication sharedAppli

我的应用程序中有以下代码——我在评论中看到了iOS 7上的一些崩溃

+ (void)registerDeviceForRemoteNotifications {
#if !TARGET_IPHONE_SIMULATOR
    if ([[KOAAuthenticator sharedAuthenticator] currentUser] != nil) {
        UIApplication *sharedApplication = [UIApplication sharedApplication];
#ifdef __IPHONE_8_0
        [sharedApplication registerForRemoteNotifications]; // <--- CRASH HERE
#else
        [sharedApplication registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert];
#endif
    }
#endif
}

ifdef是在编译(或者更确切地说是预处理)时计算的,而不是在运行时,因此构建的二进制文件中包含两个registerForRemoteNotifications调用中的哪一个只取决于使用哪个SDK构建,而不是它在哪个设备上运行。

您的代码只添加了对在旧版本的Xcode和iOS SDK上编译的支持

应在运行时添加以下检查:

#ifdef __IPHONE_8_0
        if(NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1) {
            [sharedApplication registerForRemoteNotifications]; // <--- CRASH HERE
        }
        else
#endif
        {
            [sharedApplication registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert];
        }
#ifdef_uuiPhone_8_0
如果(NSFoundationVersionNumber>NSFoundationVersionNumber\u iOS\u 7\u 1){

[sharedApplication registerForRemoteNotifications];//您可能希望将#else更改为#endif,以保留调用旧方法的代码,即使在使用较新的SDK构建时也是如此。(当前代码无法编译。)我在我的答案中添加了一个解决方案;这样应该没问题,对吧?@mstorsjo Oops会解决的。编译器时间和运行时间是两件不同的事情……我知道;但我想这应该可以工作——在iOS 8和更高版本上可以调用
寄存器或消息类型
,否则
寄存器或消息类型
,对吗?不。这就是决定在编译器时间内进行初始化。如果基本SDK iOS8,则该方法将编译为二进制:
–registerforremotentifications
,如果基本SDK iOS7,则该方法将编译为二进制:
–registerforremotentificationtypes:
。在这种情况下,与以后的运行时环境无关,请注意因为宏是编译器时间功能,它们在任何级别上都没有连接到运行时。我想这不是真的。如果是基本SDK iOS8,则If-else部分以二进制形式编译。如果是基本SDK iOS7,则将
registerForRemoteNotificationTypes:
编译为二进制形式。
#ifdef __IPHONE_8_0
        if(NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1) {
            [sharedApplication registerForRemoteNotifications]; // <--- CRASH HERE
        }
        else
#endif
        {
            [sharedApplication registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert];
        }