Ios newbie It is necessary to send an array of IT media with tweet. I get an error, I can not understand why, I did not find an example either.

2016-10-27 13:42:57.244 Twishort[89387:28692145] error saving session: Error Domain=TWTRGenericKeychainItemErrorDomain Code=-34018 "Error Code: -34018: Unknown Keychain error code." UserInfo={NSLocalizedDescription=Error Code: -34018: Unknown Keychain error code.} 2016-10-27 13:43:06.553 Twishort[89387:28680054] -[Swift._SwiftDeferredNSArray stringByAddingPercentEncodingWithAllowedCharacters:]: unrecognized selector sent to instance 0x608000039620 2016-10-27 13:43:06.561 Twishort[89387:28680054] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Swift._SwiftDeferredNSArray stringByAddingPercentEncodingWithAllowedCharacters:]: unrecognized selector sent to instance 0x608000039620' *** First throw call stack: ( 0 CoreFoundation 0x000000010fed434b __exceptionPreprocess + 171 1 libobjc.A.dylib 0x000000010f93521e objc_exception_throw + 48 2 CoreFoundation 0x000000010ff43f34 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132 3 CoreFoundation 0x000000010fe59c15 ___forwarding___ + 1013 4 CoreFoundation 0x000000010fe59798 _CF_forwarding_prep_0 + 120 5 Twishort 0x000000010b733c7f +[TWTRNetworkingUtil percentEscapedQueryStringWithString:encoding:] + 117 6 Twishort 0x000000010b733adb +[TWTRNetworkingUtil queryStringFromParameters:] + 425 7 Twishort 0x000000010b72591c -[TwitterNetworking URLRequestWithMethod:URL:parameters:] + 187 8 Twishort 0x000000010b7779f3 -[TWTRAPIClient URLRequestWithMethod:URL:parameters:error:] + 127 9 Twishort 0x000000010b705614 _TFC8Twishort6PostVC11sendTwitterfT10resultTextSS6clientCSo13TWTRAPIClient_T_ + 1300 10 Twishort 0x000000010b705031 _TFC8Twishort6PostVC7twitterfT10resultTextSS_T_ + 817 11 Twishort 0x000000010b704ada _TFFC8Twishort6PostVC12sendTwishortFT_T_U_FGV9Alamofire12DataResponseP__T_ + 2874 12 Alamofire 0x000000010bd94f59 _TFFFC9Alamofire11DataRequest8responseuRxS_30DataResponseSerializerProtocolrFT5queueGSqCSo13DispatchQueue_18responseSerializerx17completionHandlerFGVS_12DataResponsewx16SerializedObject_T__DS0_U_FT_T_U_FT_T_ + 889 13 Alamofire 0x000000010bd94fb7 _TTRGRx9Alamofire30DataResponseSerializerProtocolrXFo___XFdCb___ + 39 14 libdispatch.dylib 0x0000000112c86980 _dispatch_call_block_and_release + 12 15 libdispatch.dylib 0x0000000112cb00cd _dispatch_client_callout + 8 16 libdispatch.dylib 0x0000000112c908d6 _dispatch_main_queue_callback_4CF + 406 17 CoreFoundation 0x000000010fe984f9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9 18 CoreFoundation 0x000000010fe5df8d __CFRunLoopRun + 2205 19 CoreFoundation 0x000000010fe5d494 CFRunLoopRunSpecific + 420 20 GraphicsServices 0x000000011270aa6f GSEventRunModal + 161 21 UIKit 0x000000010e0e7f34 UIApplicationMain + 159 22 Twishort 0x000000010b6fff9f main + 111 23 libdyld.dylib 0x0000000112cfc68d start + 1 24 ??? 0x0000000000000001 0x0 + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException 2016-10-27 13:43:07.868626 Twishort[89387:28693304] [] nw_endpoint_flow_protocol_connected [9.1 199.16.156.52:443 in_progress socket-flow (satisfied)] Output protocol connected 

I understand the problem in as [String : Any] , because let parameters = ["media_ids": idImage! as String] let parameters = ["media_ids": idImage! as String] comes in normally ..

 func sendTwitter(resultText: String, client: TWTRAPIClient) { let statusesShowEndpointUpdate = "https://api.twitter.com/1.1/statuses/update.json" let parameters = ["status": resultText, "media_ids": [idImage! as String]] as [String : Any] // let parameters = ["media_ids": idImage! as String] var clientError : NSError? let requestUpdate = client.urlRequest(withMethod: "POST", url: statusesShowEndpointUpdate, parameters: parameters, error: &clientError) client.sendTwitterRequest(requestUpdate) { (response, data, connectionError) -> Void in if connectionError != nil { print("Error: \(connectionError)") } do { self.textField.text = "" let json = try JSONSerialization.jsonObject(with: data!, options: []) print("json: \(json)") } catch let jsonError as NSError { print("json error: \(jsonError.localizedDescription)") } } } 
  • In the parameters should be Dixenary string to string. I think that you need to uploadMedia: to upload a picture - markov
  • So if media_ids is an id media array, how will the parameter be a string? uploadMedia is used before, idMedia is a string with id - hailovigor
  • one
    And, well, then it is necessary to read the specification of api, there most likely it is necessary to score them, separated by commas. componentsJoinedByString on that array try - markov
  • He also thought so, because he simply ate a string instead of an array. I'll try later - hailovigor

1 answer 1

The problem is "unrecognized selector sent to instance 0x608000039620", that is, an unidentified selector.

Most likely in the name of the method "POST"

 let requestUpdate = client.urlRequest(withMethod: "POST", url: statusesShowEndpointUpdate, parameters: parameters, error: &clientError)