2010-07-13 87 views
0

我有一個iPhone應用程序使用同步服務與桌面版本同步其數據,一切工作正常,除了圖像。同步圖像使用從iPhone到OS X的同步服務

在iphone上,我在文檔目錄中存儲圖像,並在核心數據中存儲文件的路徑。我設置了一個瞬態屬性「圖像」,並檢查了同步複選框並將其分配爲標識屬性。我加了兩個方法,

- (NSData *)image; 
{ 
    NSLog(@"%@:%s entered", [self class], _cmd); 
    if (image) return image; 
    NSString *path = [self primitiveValueForKey:@"pathToFile"]; 
    if (!path) return nil; 
    NSString *myPath = [NSHomeDirectory() stringByAppendingPathComponent:path]; 
    image = [[NSData alloc] initWithContentsOfFile:myPath]; 
    return image; 
} 

- (void)setImage:(NSData *)data 
{ 
    NSLog(@"%@:%s entered", [self class], _cmd); 
    NSString *destPath = [self primitiveValueForKey:@"pathToFile"]; 
    if (!destPath) { 
    //Build the path we want the file to be at 
    destPath = NSHomeDirectory(); 
    NSString *guid = [[NSProcessInfo processInfo] globallyUniqueString]; 
    NSString *fpath = [NSString stringWithFormat:@"Documents/%@", guid]; 
    destPath = [destPath stringByAppendingPathComponent:fpath]; 
    [self setValue:destPath forKey:@"pathToFile"]; 
    } 
    [data writeToFile:destPath atomically:NO]; 
    [data retain]; 
    [image release]; 
    image = data; 
} 

- (void)willTurnIntoFault 
{ 
    [image release], image = nil; 
} 

我想,因爲我加在客戶端的說明文件中的圖像屬性,它只是把數據發送到ZSync守護程序的存儲文件,但我錯了。並且圖像數據不傳輸

我的問題是可以這樣做嗎?或什麼是同步圖像數據的最佳方式?

請給我指導,我已經搜索和搜索,但沒有找到任何解決方法。

謝謝

回答

0

有一個關於Marcus Zarra's speech on the NSConference圖像/二進制數據同步的問題。

基本上:如果你的圖像低於100k,把它作爲NSData直接放在對象內。

大於100k及以下1M使用額外的實體來存儲數據並通過關係鏈接。

1M以上存儲路徑和磁盤上的數據,就像你在做什麼。

只有前兩種方法才能從通過zsync進行同步獲益。如果你走第三步,你將不得不通過其他方式將數據帶到另一邊。

+0

我知道。我需要知道這些其他手段是什麼 – creativeKoder 2010-07-13 12:09:27

+0

爲什麼真實數據庫中的圖像數據不會被髮送到瞬態屬性,然後存儲在iPhone文件系統中,並且保存在pathToFile屬性中的路徑? – creativeKoder 2010-07-13 18:20:44