常规 -> BackgroundAppRefr-6ren">
gpt4 book ai didi

objective-c - performSelector "backgroundRefreshStatus"在 iOS 7 上崩溃

转载 作者:行者123 更新时间:2023-12-02 04:46:01 26 4
gpt4 key购买 nike

我正在使用 Xcode 5/iOS SDK 6.1 进行构建。如果应用程序在 iOS 7.x 设备上运行,它应该检查是否为应用程序设置了设置“设置 -> 常规 -> BackgroundAppRefresh”。由于此属性仅在 iOS 7 上可用,我正在做:

if([[UIApplication sharedApplication] respondsToSelector:@selector(backgroundRefreshStatus)])
{
NSInteger outcome=[[[UIApplication sharedApplication] performSelector:@selector(backgroundRefreshStatus)] integerValue];
//do something with "outcome"
}

但是...该应用程序在 iOS 7 上的“performSelector”行崩溃,这很奇怪,因为它传递了“respondsToSelector”调用?任何人都知道为什么?我还尝试了 NSSelectorFromString(@"backgroundRefreshStatus"),结果相同。

最佳答案

那里有很多不必要的代码。除非 backgroundRefreshStatus 选择器在 iOS 7 之前作为私有(private) API 存在,否则您不需要版本检查。

你对@selector的使用也是不正确的,你不需要使用performSelector,调用方法即可:

if ([[UIApplication sharedApplication] respondsToSelector:@selector(backgroundRefreshStatus)]) {
UIBackgroundRefreshStatus refreshStatus = [[UIApplication sharedApplication] backgroundRefreshStatus];
}

关于objective-c - performSelector "backgroundRefreshStatus"在 iOS 7 上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19793766/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com