2012-03-10 76 views
2

我有一個簡單的(我認爲)的問題:Xcode上傳一個plist文件在服務器上(iPhone)

我有一個iPhone。他創建一個plist文件並保存。我想在服務器上上傳這個文件。

然後,與其他3個iPhone,我將下載此plist文件並解密信息。

我的問題是:如何將這個plist文件上傳到服務器! 我沒有任何FTP服務器或其他...我可以用Dropbox來代替嗎? 或者是iPhone之間進行通信的另一種方式(私有 - 不適用於AppStore)?

非常感謝您的回答!

回答

1

是的,您可以使用Dropbox API在Dropbox用戶的文件夾中上傳plist。

首先檢查this link設置你的項目

您可以使用這些片段(from this page):

NSString *localPath = [[NSBundle mainBundle] pathForResource:@"Info" ofType:@"plist"]; 
NSString *filename = @"Info.plist"; 
NSString *destDir = @"/"; 
[[self restClient] uploadFile:filename toPath:destDir 
        withParentRev:nil fromPath:localPath]; 

然後實現回調

- (void)restClient:(DBRestClient*)client uploadedFile:(NSString*)destPath 
    from:(NSString*)srcPath metadata:(DBMetadata*)metadata { 

    NSLog(@"File uploaded successfully to path: %@", metadata.path); 
} 

- (void)restClient:(DBRestClient*)client uploadFileFailedWithError:(NSError*)error { 
    NSLog(@"File upload failed with error - %@", error); 
} 

編輯: (如果您想要,您可以從a的Documents文件夾中加載plist第記得mainBundle是隻讀的,所以你不能修改駐留在主束plist中,你只能讀它)..這樣的:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES); 
NSString *plistFilePath = [[paths objectAtIndex:0]stringByAppendingPathComponent:@"info.plist"]; 
NSDictionary *plistFile = [[NSMutableDictionary alloc] initWithContentsOfFile:plistFilePath]; 
+0

你是一個高手!非常感謝您的幫助 ! – 2012-03-10 21:35:34

+0

有一個小問題(對不起)! 如何從我的應用程序的Documents文件夾加載plist?它被稱爲「Menu.plist」 再次感謝您! – 2012-03-10 22:36:10

+0

@WaesAntoine檢查我的edit..remember檢查答案接受(並upvote它,如果你想)如果它對你有用:) – Mat 2012-03-13 01:09:24