NSURLIsExcludedFromBackupKey在iOS 5.1之前崩溃 [英] NSURLIsExcludedFromBackupKey crashes before iOS 5.1

查看:181
本文介绍了NSURLIsExcludedFromBackupKey在iOS 5.1之前崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

和许多iOS开发人员一样,当使用 NSURLIsExcludedFromBackupKey 时,我遇到了应用程序在5.1之前崩溃的问题。



很好地描述了如何评估此主题上此键的存在:



在iOS 5.0上使用NSURLIsExcludedFromBackupKey而不会崩溃



samvermette的评论之一表示iOS模拟器中有错误。



但是,即使在两个单独的应用程序中,我也遇到了 发布 构建的相同问题。
经过一番调查,我发现应用程序崩溃甚至在main()方法beeing调用之前。这暗示了我与

有关联。

NSString * const NSURLIsExcludedFromBackupKey;



评估。



我不是这个领域的专家,但我发现,如果任何引用 const 发生在代码中(即使它在运行时实际上没有被访问),这个 const 在应用程序启动时被评估。这只会导致我们很多人经历的崩溃。



我想问你一些帮助。也许你知道一个方法如何弱引用一个const值,或者也许有特定的编译器标志。 (使用Apple LLVM 3.1)。



提前感谢。



这个const的值直接是@NSURLIsExcludedFromBackupKey在这种情况下。我知道这个解决方法,这个故事的共鸣是找到一个一般的解决方案。


解决方案

解决方案,感谢 http://stackoverflow.com/a/9620714/127493

  NSString * const NSURLIsExcludedFromBackupKey; 

不是弱链接的,即使Base SDK设置为iOS 5.1,与 SDK兼容性指南说。



诀窍是使用此const的结果。

如果我这样做

  NSLog(@%@,NSURLIsExcludedFromBackupKey); 

结果是 @NSURLIsExcludedFromBackupKey / p>

所以我生成的代码是

  #define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO [[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch]!= NSOrderedAscending)

NSError * error = nil;
BOOL成功;
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@5.1)){
success = [storeURL setResourceValue:[NSNumber numberWithBool:YES] forKey:@NSURLIsExcludedFromBackupKeyerror:& error];
}


Like many of iOS developers I have encountered the issue with application crashing on system before 5.1 when using NSURLIsExcludedFromBackupKey.

It was well described how to evaluate existence of this key on this thread:

Use NSURLIsExcludedFromBackupKey without crashing on iOS 5.0

One of samvermette's comments says that there is a bug in iOS simulator.

Nevertheless I have encountered the same issue with a Release build, even in 2 separate applications. After some investigation I have discovered that application crashed even before main() method beeing called. Which hinted me that this is connected with

NSString * const NSURLIsExcludedFromBackupKey;

evaluation at application launch.

I am not an expert in this field, but I have found out that, if any reference to const value occurs in code (even if it is not actually accessed in runtime) this const is evaluated at very application launch. And this simply causes that crash that many of us experience.

I would like to ask you for some help. Maybe you know a way how to 'weakly' refer to a const value, or maybe there is specific compiler flag. (Using Apple LLVM 3.1).

Thanks in advance.

Please do not comments to put this const's value directly which is @"NSURLIsExcludedFromBackupKey" in this case. I am aware of this workaround, reson for this story is to find a general solution.

解决方案

I found a solution, thanks to http://stackoverflow.com/a/9620714/127493 !

NSString * const NSURLIsExcludedFromBackupKey;

is NOT weak-linked, even if Base SDK is set to iOS 5.1, unlike the SDK Compatibility Guide says.

The trick is to use the result of this const.
If I do

NSLog(@"%@", NSURLIsExcludedFromBackupKey);

the result is @"NSURLIsExcludedFromBackupKey"

So my resulting code is

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

NSError * error = nil;
BOOL success;
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"5.1")) {
    success = [storeURL setResourceValue:[NSNumber numberWithBool:YES] forKey:@"NSURLIsExcludedFromBackupKey" error:&error];
}

这篇关于NSURLIsExcludedFromBackupKey在iOS 5.1之前崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆