2013-03-20 1 views
1

TWRequest 객체를 사용하여 이미지를 게시하려고합니다. 프로그램이 [request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {으로 라인에 도달 할 때마다TWRequest로 게시하려고 할 때 "인식 할 수없는 선택기를 인스턴스로 보냄"받기

ACAccountStore *accountStore = [[ACAccountStore alloc] init]; 
    ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; 
    NSData *pngImage = UIImagePNGRepresentation(image); 
    NSData *tweetText = [userText copy]; 
    [accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) { 
     if (granted) { 
      NSLog(@"Twitter is good to go"); 
      NSArray *twitterAccounts = [accountStore accountsWithAccountType:accountType]; 
      if (twitterAccounts.count) { 
       ACAccount *twitterAccount = [twitterAccounts objectAtIndex:0]; 
       NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/1.1/statuses/update_with_media.json"]; 
       TWRequest *request = [[TWRequest alloc] initWithURL:url parameters:nil requestMethod:TWRequestMethodPOST]; 
       [request addMultiPartData:pngImage withName:@"media" type:@"image/png"]; 
       [request addMultiPartData:tweetText withName:@"text" type:@"text/plain"]; 
       [request setAccount:twitterAccount]; 
       [request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { 
        if (responseData) 
        { 
         NSError *error = nil; 
         NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error]; 
         if (jsonArray) { 
          for(NSDictionary *item in jsonArray) { 
           NSLog(@"Item: %@", item); 
          } 
         } 
         else 
         { 
          NSLog(@"Error %@ with user info %@.", error, error.userInfo); 
         } 
        } 
       }];         
      } 
     } else { 
      NSLog(@"The user does not grant us permission to access its Twitter account(s)."); 
     } 
    }]; 

나는 다음과 같은 오류 얻을 : 여기 내 코드의

[__NSCFString bytes]: unrecognized selector sent to instance 0x1d8f4250 * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString bytes]: unrecognized selector sent to instance 0x1d8f4250' * First throw call stack: (0x33ec02a3 0x3bb5a97f 0x33ec3e07 0x33ec2531 0x33e19f68 0x3473b90b 0x35c416fd 0x35c417a3 0x35c4065f 0x35c3fa6b 0x35c40ab9 0x5adc5 0x3bf7211f 0x3bf7fdcb 0x3bf80259 0x3bf803b9 0x3bfa6a11 0x3bfa68a4) libc++abi.dylib: terminate called throwing an exception (lldb)

답변

6

문제는 tweetText와 함께입니다. NSString을 복사 중이지만 NSData 개체에 할당 중입니다.

NSData *tweetText = [userText copy]; 

이것 :이

변경

NSData *tweetText = [userText dataUsingEncoding:NSUTF8StringEncoding]; 
관련 문제