時間真的是過得飛快,一週過去,現在來總結想想,好像都沒有什麼收穫。這是一件讓人非常惱怒的事情,明明每天都加班,明明連週六都在上班,錢沒多拿,經驗和知識卻沒有增加。上一週主要是在同事做過的模塊裏添加新功能,由於同事去做新的遊戲,原先的應用完全由我來維護。同事的代碼不錯,採用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 = 1;
int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0);
return result == 0;
}
沒有找到好的檢測版本的方法,就用了最土的一種:
</pre><pre name="code" class="objc">NSURL *tempURL = [NSURL fileURLWithPath:[NSString stringWithUTF8String:(CCFileUtils::sharedFileUtils()->getWritablePath()+"temp/").c_str()]];
NSString *stringVersion =[[UIDevice currentDevice] systemVersion];
NSArray * array = [stringVersion componentsSeparatedByString:@"."];
int symbol = 0;
for (NSInteger i = 0; i < array.count; ++ i) {
if (i == 0) {
if ([[array objectAtIndex:i] integerValue] > 5) {
symbol = 3;
break;
}else if([[array objectAtIndex:i] integerValue] < 5){
symbol = 0;
break;
}
}else if(i == 1){
if ([[array objectAtIndex:i] integerValue] >= 1) {
symbol = 3;
break;
}
}else if(i == 2){
if ([[array objectAtIndex:i] integerValue] > 0) {
symbol = 2;
break;
}
}
}
NSLog(@"the symbol is %d", symbol);
// [self addSkipBackupAttributeToItemAtURL:tempURL];
if (symbol == 2) {
[self addSkipBackupAttributeToItemAtURLLow:tempURL];
}else if(symbol == 3){
[self addSkipBackupAttributeToItemAtURLHigh:tempURL];
}
值得注意的是:5.0一下的不存在icloud檢測;不允許將document整個目錄作爲icloud忽略目錄;檢測V5.0.1時需要導入sys/xattr.h