0
서버 응답을 받았지만 plist에 저장하려고했지만 plist 파일이 작성되지 않았습니다.Plist가 Objective C로 작성되지 않았습니다
나는 파일 경로와 사전 내용을 기록했지만 이러한 모든 데이터는 여전히 방법
-(void)sideMenu:(NSString *)title{
NSString *myRequestString = [[NSString alloc] initWithFormat:@"data=%@&deviceid=e8ef8c98262185ec",title];
NSData *myRequestData = [NSData dataWithBytes:[myRequestString UTF8String ] length: [ myRequestString length ] ];
NSMutableURLRequest *request = [ [ NSMutableURLRequest alloc ] initWithURL: [ NSURL URLWithString:SIDE_MENU]];
[request setHTTPMethod:@"POST"];
[request setHTTPBody: myRequestData];
NSURLResponse *response;
NSError *err;
NSData *returnData = [NSURLConnection sendSynchronousRequest: request returningResponse:&response error:&err];
NSString* responseString = [[NSString alloc] initWithData:returnData encoding:NSNonLossyASCIIStringEncoding];
NSArray *myArray = [responseString componentsSeparatedByString:@"<!DOC"];
//NSLog(@"%@",myArray);
if (myArray != nil || [myArray count] > 0) {
NSData *data = [[[myArray objectAtIndex:0]stringByReplacingOccurrencesOfString:@"\n" withString:@""] dataUsingEncoding:NSUTF8StringEncoding];
id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
[self sideMenuFile:title :json];
}
}
-(NSString *)sideMenuFile:(NSString *)titleName :(NSDictionary *)dict{
NSString *filePath;
MyManager *sharedManager =[MyManager sharedManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
if([titleName isEqualToString:@"ML"])
{ sharedManager.sideMenu = [[NSDictionary alloc]init];
sharedManager.sideMenu = dict;
filePath = [documentsDirectory stringByAppendingPathComponent:@"ML.plist"];
}else if ([titleName isEqualToString:@"HM"]){
filePath = [documentsDirectory stringByAppendingPathComponent:@"HM.plist"];
}else if ([titleName isEqualToString:@"PDC"]){
filePath = [documentsDirectory stringByAppendingPathComponent:@"PDC.plist"];
}else if ([titleName isEqualToString:@"SM"]){
filePath = [documentsDirectory stringByAppendingPathComponent:@"SM.plist"];
}else if ([titleName isEqualToString:@"GL"]){
filePath = [documentsDirectory stringByAppendingPathComponent:@"GL.plist"];
}else if ([titleName isEqualToString:@"CU"]){
filePath = [documentsDirectory stringByAppendingPathComponent:@"CU.plist"];
}else if ([titleName isEqualToString:@"BR"]){
filePath = [documentsDirectory stringByAppendingPathComponent:@"GL.plist"];
}
NSLog(@"%@",filePath); //printing path
[dict writeToFile:filePath atomically:YES];
NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
NSString *plistName = @"GL";
NSString *finalPath = [basePath stringByAppendingPathComponent:
[NSString stringWithFormat: @"%@.plist", plistName]];
NSDictionary *dictww=[[NSDictionary alloc]initWithContentsOfFile:finalPath];
NSLog(@"dict%@",dictww); //printing nill
return filePath;
}
JSON 파일 구조
{
sigallery = {
rows = (
{
active = True;
gallerytext = "<null>";
galleryurl = "assets/img/content-images/1.jpg";
moddt = "2016-07-19T12:28:18.873";
onclickurl = "testd.in";
settingsid = 1;
showfromdt = "1901-01-01T00:00:00.0";
showsequence = 1;
showuptodt = "2099-12-31T00:00:00.0";
videoimagebanneraudioswitch = I;
},
{
active = True;
gallerytext = "<null>";
galleryurl = "assets/img/content-images/2.jpg";
moddt = "2016-07-19T12:28:18.873";
onclickurl = "testd.in";
settingsid = 1;
showfromdt = "1901-01-01T00:00:00.0";
showsequence = 2;
showuptodt = "2099-12-31T00:00:00.0";
videoimagebanneraudioswitch = I;
}
)
}
}
참조 - http://stackoverflow.com/questions/12170871/how-to-add-a-key-value-pair-to-a-plist-file-in-objective-c 및 http : // stackoverflow .com/questions/23867337/i-save-retrieve-delete-update-my-data-in-plist-file-in-ios – Signare
[finalPath isEqualToString : filePath]? 메서드 선언/sideMenuFile : noTextHere :는 권장하지 않습니다. – Larme