首页 > 代码库 > ios指定目录不进行icloud检测
ios指定目录不进行icloud检测
时间真的是过得飞快,一周过去,现在来总结想想,好像都没有什么收获。这是一件让人非常恼怒的事情,明明每天都加班,明明连周六都在上班,钱没多拿,经验和知识却没有增加。上一周主要是在同事做过的模块里添加新功能,由于同事去做新的游戏,原先的应用完全由我来维护。同事的代码不错,采用MVC结构,结构剥离的相当明确,C层采用一个驱动,驱动里面嵌套了一个状态机。M数据采用装饰者模式嵌入C 层,利用事件响应机制来实现C层与V层的通讯。比较有价值的应该是他实现状态机的过程,可惜我要赶项目,而且当时编译原理也没学透彻,所以有点囫囵吞枣了。再者就是看同事定义的与后台的协议了,我们现在的做的是德州扑克的回放,状态比较多。着实是花了一些时间去看,代码是如何读取数据的。
当然这不是一篇抱怨的文章,虽然我老是抱怨这抱怨那的,其实我也挺讨厌那样的自己,只是控制不住罢了。比较有意义的一点可能是如何绕过ios的icloud审核。我们的应用是一个弱联网的,为了节省用户流量因此在app里面预存了一些数据。在程序第一次运行时,将数据从程序包拷贝到document目录。由于这个原因,app被app store拒绝过一次,提示程序未做任何操作,但是icloud多了一些数据。
绕过的方法如下:
- (BOOL)addSkipBackupAttributeToItemAtURLHigh:(NSURL *)URL { // 5.1 + assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]); NSError *error = nil; BOOL success = [URL setResourceValue: [NSNumber numberWithBool: YES] forKey: NSURLIsExcludedFromBackupKey error: &error]; if(!success){ NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error); } return success; } - (BOOL)addSkipBackupAttributeToItemAtURLLow:(NSURL *)URL { // 5.0.1: assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]); const char* filePath = [[URL path] fileSystemRepresentation]; const char* attrName = "com.apple.MobileBackup"; u_int8_t attrValue = http://www.mamicode.com/1;>没有找到好的检测版本的方法,就用了最土的一种:
<p class="p1"><span class="s1"> </span><span class="s2">NSURL</span><span class="s1"> *tempURL = [</span><span class="s2">NSURL</span><span class="s1"> </span>fileURLWithPath<span class="s1">:[</span><span class="s2">NSString</span><span class="s1"> </span>stringWithUTF8String<span class="s1">:(</span><span class="s3">CCFileUtils</span><span class="s1">::</span><span class="s4">sharedFileUtils</span><span class="s1">()-></span><span class="s4">getWritablePath</span><span class="s1">()+</span><span class="s5">"temp/"</span><span class="s1">).</span>c_str<span class="s1">()]];</span></p><p class="p2"> </p><p class="p3"> <span class="s2">NSString</span> *stringVersion =[[<span class="s2">UIDevice</span> <span class="s6">currentDevice</span>] <span class="s6">systemVersion</span>];</p><p class="p3"> <span class="s2">NSArray</span> * array = [stringVersion <span class="s6">componentsSeparatedByString</span>:<span class="s5">@"."</span>];</p><p class="p3"> <span class="s7">int</span> symbol = <span class="s8">0</span>;</p><p class="p3"> <span class="s7">for</span> (<span class="s2">NSInteger</span> i = <span class="s8">0</span>; i < array.<span class="s6">count</span>; ++ i) {</p><p class="p3"> <span class="s7">if</span> (i == <span class="s8">0</span>) {</p><p class="p3"> <span class="s7">if</span> ([[array <span class="s6">objectAtIndex</span>:i] <span class="s6">integerValue</span>] > <span class="s8">5</span>) {</p><p class="p3"> symbol = <span class="s8">3</span>;</p><p class="p3"> <span class="s7">break</span>;</p><p class="p3"> }<span class="s7">else</span> <span class="s7">if</span>([[array <span class="s6">objectAtIndex</span>:i] <span class="s6">integerValue</span>] < <span class="s8">5</span>){</p><p class="p3"> symbol = <span class="s8">0</span>;</p><p class="p3"> <span class="s7">break</span>;</p><p class="p3"> }</p><p class="p3"> }<span class="s7">else</span> <span class="s7">if</span>(i == <span class="s8">1</span>){</p><p class="p3"> <span class="s7">if</span> ([[array <span class="s6">objectAtIndex</span>:i] <span class="s6">integerValue</span>] >= <span class="s8">1</span>) {</p><p class="p3"> symbol = <span class="s8">3</span>;</p><p class="p3"> <span class="s7">break</span>;</p><p class="p3"> }</p><p class="p3"> }<span class="s7">else</span> <span class="s7">if</span>(i == <span class="s8">2</span>){</p><p class="p3"> <span class="s7">if</span> ([[array <span class="s6">objectAtIndex</span>:i] <span class="s6">integerValue</span>] > <span class="s8">0</span>) {</p><p class="p3"> symbol = <span class="s8">2</span>;</p><p class="p3"> <span class="s7">break</span>;</p><p class="p3"> }</p><p class="p3"> }</p><p class="p3"> }</p><p class="p3"> <span class="s7">if</span> (symbol == <span class="s8">2</span>) {</p><p class="p4"><span class="s1"> [</span><span class="s7">self</span><span class="s1"> </span>addSkipBackupAttributeToItemAtURLLow<span class="s1">:tempURL];</span></p><p class="p3"> }<span class="s7">else</span> <span class="s7">if</span>(symbol == <span class="s8">3</span>){</p><p class="p4"><span class="s1"> [</span><span class="s7">self</span><span class="s1"> </span>addSkipBackupAttributeToItemAtURLHigh<span class="s1">:tempURL];</span></p><p class="p3"> }</p>值得注意的是:5.0一下的不存在icloud检测;不允许将document整个目录作为icloud忽略目录;检测V5.0.1时需要导入sys/xattr.hios指定目录不进行icloud检测
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。