We developed the iphone app which will be used by employees of the diff. organizations (actually we have not made it enterprise app , instead we are going to put this app on app store for the charge) , So whats we want is whenever the person will install the app, and the app will open first time , one pop up will come over there asking for the enter URL (which will be the URL points to the server of that persons organization) , So going through code logic , what i want is when we will come to the login page in the view did load i want to check whether the URL is already stored in the app or not, if its not stored then i will give that pop up asking for enter URL, and if its stored then simply i will allow him to enter the login details.
My problem is how should i store that URL and where should i store that URL and How should i check whether that is already stored or not. I tried to store that URL with… Where the urlfield.text is the URL i am going to store.
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]);
and i am checking whether its there or not using..
// fileExists is a BOOL variable
fileExists = [[NSFileManager defaultManager] fileExistsAtPath:filePath];
NSLog(@"Boolean value:=%d",fileExists);
if ( fileExists == 0 )
{
.......
........
}
but each time i runs the app it returns the ‘0’ (means the BOOL variable fileExists) .
please some one will tell me the way to accomplish my task, I am end up with trying all the sides with this logic.
i use the NSUserDefaults for this.
first upon for checking that whether the user is opening the app first time i check the value for the first object of NSUserDefault like
the URLEntered returns null at first time, so i set the value 0 for Key URLISENTERED
and i allowed users to enter the URL of there organizations server,
within that i set the valu for key URLISENTERED as a 1 , like
and at the same time i take one more object of NSUserDefault to store the URL of the server and stored that like
so next when the user again logins to the app the value of
is 1 as we set and that time i navigated user to login screen directly , and have fetched the value of mainURL using
and used this URL for further use.