1
iPhone 응용 프로그램을 작성합니다. 이 응용 프로그램에서는 트위터 프레임 워크를 사용합니다. 이 프레임 워크에서, 동기화 해제 된 콜백 함수는 다른 스레드에 있습니다. 내보기 컨트롤러에서 Objective-C의 다른 스레드에서 NSURLConnection에 의한 데이터를 수신하는 방법
,ViewController.m
[accountStore requestAccessToAccountsWithType:accountType
withCompletionHandler:^(BOOL granted, NSError *error) {
if (granted) {
if (account == nil) {
NSArray *accountArray = [accountStore accountsWithAccountType:accountType];
account = [accountArray objectAtIndex:2];
}
if (account != nil){
NSURL *url = [NSURL URLWithString:@"http://api.twitter.com/1/statuses/user_timeline.json"];
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
[params setObject:@"1" forKey:@"count"];
TWRequest *request = [[TWRequest alloc] initWithURL:url
parameters:params
requestMethod:TWRequestMethodGET];
[request setAccount:account];
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
if (responseData) {
//Throw response data to other Web API
[self otherAPI:responseData];
[[NSRunLoop currentRunLoop] run];
}
}];
}
}
}];
그리고이 클래스에서 이러한 방법을 쓰기.
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response;
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data;
- (void)connectionDidFinishLoading:(NSURLConnection *)connection;
하지만 다른 API에서 전체 데이터를받을 수 없습니다. 첫 번째 데이터 만받을 수 있습니다. 다중 스레드를 수행 할 때 몇 가지 문제가 있다고 생각합니다. 따라서이 코드에서 무엇이 잘못되었는지 알려주고 싶습니다.
해 주셔서 감사합니다. 그러나 나는 이미 그 선택을했습니다. 그 후, 나는이 문제를 해결했다. 나는 일본어를 사용한다. 그래서 - (NSString *) stringByAddingPercentEscapesUsingEncoding 메서드는 필요한 것처럼 보입니다. 전체 데이터를받을 수 있습니다. NSLog는 이스케이프 처리되지 않은 데이터를 표시 할 수 없다고 생각합니다. 고맙습니다. – Lewuathe