home

2014년 10월 2일 목요일

[iOS] 서버 연동 app을 만들기 위한 준비 AFNetworking, JSONKit

1. iOS app을 만들자.
1.1 간단히 tabbar만 붙여서 webview로 만들자.
1.1.1 Custom Tabbar를 만들자
http://code4app.net/category/tabbar : 탭바 예제들

2. 컨셉수정됐다.
2.1. 홈 화면은 app에서 구성해서 선택하면 web을 보여주자 ㅜㅜ
2.2. php서버와 통신법을 찾아보자.

2.2.1.
http://www.raywenderlich.com/2941/how-to-write-a-simple-phpmysql-web-service-for-an-ios-app
http://blog.naver.com/trick14/100187935170 : 간단한 php, AFHttpRequest예제 설명

2.2.2. 비동기로 쓰자.
http://seorenn.blogspot.kr/2012/04/ios.html

2.2.3. AFHttpRequest를 쓰자
http://www.raywenderlich.com/59255/afnetworking-2-0-tutorial : Weather app예제를 통한 JSON, PLIST, XML방식 등 보여줌. Very Good!!.
http://jinpyolab.tistory.com/66 : POST방식
2.2.3.1 AFNetworking 라이브러리를 추가 해보기
2.2.3.1.1. https://github.com/AFNetworking/AFNetworking 가서 zip 파일을 받는다
2.2.3.1.2. AFNetworking , UIKit+AFNetworking 폴더를 내 프로젝트에 끌어다 놓는다.
2.2.3.1.3. Supporting files -> ...-Prefix.pch 파일에 #import "AFNetworking.h" 추가
2.2.3.1.4. 프로젝트 창 제일위에 프로젝트 이름 선택 -> TARGETS -> Build Phases -> Compile Sources (?? items) -> 아래 + 눌러서 추가한 AFHTTP 폴더 안에 *.m 들을 추가한다.
2.2.3.1.5. Link Binary With Libraries  -> Security.framework, SystemConfiguration.framework, MobileCoreServices.framework, CoreLocation.framework 등을 추가한다.

2.2.3.2 JSONKit 을 이용한 data parsing

2.2.3.2.1 JSONKit 다운받아서 .h .m을 서버에 추가하자
-https://github.com/johnezang/JSONKit
-http://kaojinz.tistory.com/124
#import "JSONKit.h"


NSString *filePath = [[NSBundle mainBundlepathForResource:@"items" ofType:@"json"];   
NSString *a = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];

// 클래스의 종류  내용보기 
//    NSLog(@"class:%@ a:%@",[a class], a);

// JSON NSArray NSDictionary  변환 
NSArray *array = [a objectFromJSONString];
NSLog(@"class: %@, %d", [array class], [array count]);

// Array에서 Dictionary 가져오기 
NSDictionary *dic = [array objectAtIndex:0];
NSLog(@"dic name:%@", [[dic valueForKey:@"name"description]);

-http://ahikuya.tistory.com/24
[usage]
?
1
2
3
4
5
6
7
8
9
10
11
NSString *jsonUrl = @"http://twitter.com/statuses/public_timeline.json";
NSData *jsonData = [NSData dataWithContentsOfURL:[NSURL URLWithString:jsonUrl]];
 
//NSLog(@"jsonData : %@", [jsonData objectFromJSONData]);
NSArray *items = [jsonData objectFromJSONData]; 
NSLog(@"jsonData >> class : %@, count : %d", [items class], [items count]);
//NSLog(@"jsonData >> %@", [items objectAtIndex:0]);
 
// Array에서 Dictionary 가져오기
NSDictionary *dic = [items objectAtIndex:0];
NSLog(@"dic created_at:%@", [[dic valueForKey:@"created_at"] description]);

2.2.3.2.2 빌드하면 ARC 에러가 나면? 
http://j2enty.tistory.com/107 arc에러 대처
project > target > Build Phases > Compile Sources에 보면 프로젝트에 사용되는 .m, .mm, .c, .cpp 등 파일들이 추가되어있다. 컴파일할 소스코드들을 보여주는데 여기서 문제가 되는 JSONKit.m 파일을 찾아 더블클릭한 후 나오는 창에 
  -fno-objc-arc

2.2.4 mySql, iOS 통신?
http://miinyx.wordpress.com/2011/08/25/mysql-and-objective-c-for-iphone-and-osx/

댓글 없음:

댓글 쓰기