我们开发了 diff 员工将使用的 iPhone 应用程序。组织(实际上我们还没有做企业应用,而是将这个应用放在应用商店收费),所以我们想要的是每当人们安装应用时,应用会第一次打开,一个弹出up 会过来询问输入 URL(这将是指向那个人组织的服务器的 URL),所以通过代码逻辑,我想要的是当我们到达视图中的登录页面时确实加载了我想检查 URL 是否已经存储在应用程序中,如果它没有存储,那么我会弹出要求输入 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”(表示 BOOL 变量 fileExists)。请有人告诉我完成任务的方法,我最终会用这种逻辑尝试所有方面。