// Write data to plist
// BEGIN
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingString:@"/data.plist"];
//
NSFileManager *fileManager = [NSFileManager defaultManager];
NSMutableDictionary *plistDict;
if ([fileManager fileExistsAtPath: filePath])
{
plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
}else{
plistDict = [[NSMutableDictionary alloc] init];
}
NSString *userString = @"NULL";
if ([userID.text isEqualToString:@"iosappsvisitor"]) {
userString = @"hk\\general";
}
else {
userString = userID.text;
}
NSArray *userArray = [userString componentsSeparatedByString:@"\\"
];
NSString *userIDOnly = [userArray objectAtIndex:1];
[plistDict setValue:userIDOnly forKey:@"UserID"];
[plistDict setValue:userPassword.text forKey:@"UserPwd"];
[plistDict setValue:accessKey forKey:@"UserAccessKey"];
[plistDict setValue:myIMEICode forKey:@"UserIMEI"];
if ([plistDict writeToFile:filePath atomically: YES]) {
NSLog(@"writePlist success");
} else {
NSLog(@"writePlist fail");
}
[plistDict release];