我們開發了iphone應用程序,供差異員工使用。組織(實際上我們沒有製作它的企業應用程序,相反我們打算把這個應用程序放在應用程序商店付費),因此,我們想要的是什麼時候該人將安裝該應用程序,並且該應用程序將第一次打開,一個彈出窗口會出現在那裏,詢問輸入URL(這將是指向該組織的服務器的URL),因此,通過代碼邏輯,我想要的是何時我們將訪問視圖中的登錄頁面加載我想檢查URL是否已經存儲在應用程序中,如果它沒有存儲,那麼我會給那個彈出詢問輸入URL,如果它存儲然後只是我會讓他輸入登錄細節。如何將數據存儲到iPhone應用程序
我的問題是,我應該如何存儲該URL,我應該在哪裏存儲該URL以及我應該如何檢查是否已存儲該URL。我試圖將該URL存儲在... urlfield.text是我要存儲的URL。
NSError *error;
// For error information
// Create file manager
fileMgr = [NSFileManager defaultManager];
// Point to Document directory
documentsDirectory = [NSHomeDirectory()
stringByAppendingPathComponent:@"Documents"];
fileExists = [[NSFileManager defaultManager] fileExistsAtPath:filePath];
// File we want to create in the documents directory
// Result is: /Documents/file1.txt
filePath = [documentsDirectory
stringByAppendingPathComponent:@"file1.txt"];
str=urlField.text;
// Write the file
[str writeToFile:filePath atomically:YES
encoding:NSUTF8StringEncoding error:&error];
// Show contents of Documents directory
NSLog(@"Documents directory: %@",
[fileMgr contentsOfDirectoryAtPath:documentsDirectory error:&error]);
和我檢查它的存在或者不使用是否..
// fileExists is a BOOL variable
fileExists = [[NSFileManager defaultManager] fileExistsAtPath:filePath];
NSLog(@"Boolean value:=%d",fileExists);
if (fileExists == 0)
{
.......
........
}
但每次我運行它返回「0」的應用程序(是指布爾變量FILEEXISTS)。 請有人告訴我完成我的任務的方式,我最終會用這個邏輯來嘗試所有的一面。
在檢查文件是否存在之前檢查字符串「filePath」。 –
在檢查之前是否設置了字符串「filePath」? –
@ anusha:感謝您的更新,實際上我解決了它的幫助下「NSUserDefaults」 – iShwar