2

Xcode 5/iOS SDK 6.1 でビルドしています。アプリが iOS 7.x デバイスで実行されている場合は、設定 "Settings -> General -> BackgroundAppRefresh" がアプリに設定されているかどうかを確認する必要があります。このプロパティは iOS 7 でのみ使用できるため、次のことを行っています。

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

しかし...「respondsToSelector」呼び出しを渡すため、奇妙な「performSelector」行でiOS 7でアプリがクラッシュしますか?? 誰でも理由を知っていますか?私も同じ結果で NSSelectorFromString(@"backgroundRefreshStatus") を試しました。

4

2 に答える 2

4

そこには不要なコードがたくさんあります。セレクターがプライベート API として iOS 7 より前に存在しない限り、backgroundRefreshStatusバージョン チェックは必要ありません。

の使用@selectorも正しくなく、 を使用する必要はありませんperformSelector。メソッドを呼び出すだけです。

if ([[UIApplication sharedApplication] respondsToSelector:@selector(backgroundRefreshStatus)]) {
    UIBackgroundRefreshStatus refreshStatus = [[UIApplication sharedApplication] backgroundRefreshStatus];
}
于 2013-11-05T16:31:17.720 に答える
1

セレクターとして文字列を使用しています。文字列なしで試してください:

UIApplication *app = [UIApplication sharedApplication];
if([app respondsToSelector:@selector(backgroundRefreshStatus)])
{
    UIBackgroundRefreshStatus outcome = [app performSelector:@selector(backgroundRefreshStatus)];
    // or outcome = [app backgroundRefreshStatus]
}
于 2013-11-05T16:29:57.933 に答える