ios - 使用仅适用于 iOS 7 的方法时抛出警告

标签 ios

我的应用同时支持 iOS 6iOS 7。我使用的一些方法仅在 iOS7 中可用(如 suspend),但在 iOS6 中不可用。但是,我正在为 iOS6iOS7 使用适当的分支(相应地设置条件)。但是,当我使用 suspend 方法时收到警告。

这是我的方法:

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
        UIApplication *app = [UIApplication sharedApplication];

    if([app respondsToSelector:@selector(suspend)])
    {
        [app performSelector:@selector(suspend)];

        [NSThread sleepForTimeInterval:1.0];
    }
        exit(0);
}

警告是

"Undeclared Selector 'suspend'"

最佳答案

您发布的代码有几处错误。

  1. UIApplication 没有名为suspend 的公共(public)方法。您似乎在尝试调用私有(private) API。编译器提示,因为它找不到名为 suspend 的方法(因为找不到公共(public)方法)。附带说明一下,这很可能会导致您的应用被 Apple 拒绝。

  2. 永远不要在主线程上休眠。非常糟糕。

  3. 永远不要调用exit。这是不允许的。

关于ios - 使用仅适用于 iOS 7 的方法时抛出警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21424871/

相关文章:

ios - PWA 重定向到登录页面并陷入 2FA 循环

ios - 从 JSON + Swift 或 ObjC 检索数据时如何处理 CoreData 中的关系

iphone - 未调用核心数据验证方法 - iPhone

ios - 是否可以强制 NSUbiquitousKeyValueStore 从云端提取更新?

ios - 在指定时间间隔使用 CoreLocation 在后台检索 CoreMotion 数据

iphone - 在 Flash 上运行 iOS 应用程序

ios - 2012年是否支持iOS 3.x?

ios - 当应用程序未运行 IOS 时播放警报声音

ios - 几天后PFUser currentUser返回null

ios - Objective-C类别未链接