I'm trying to upload a NSData which is image using AFNetwork but something going wrong which i cannot find where is my mistake
here is my code:
NSData *imageData = UIImageJPEGRepresentation([UIImage imageNamed:#"test.jpg"], 0.1);
NSMutableDictionary *postParams = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"this is only a test post for \"app\".", #"app",
#"this POST for \"test\". ", #"test", nil];
NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:#"POST" URLString:#"http://url/upload.php" parameters:postParm constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileData:imageData name:#"file" fileName:#"filename.jpg" mimeType:#"image/jpeg" ];
} error:nil];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
NSProgress *progress = nil;
NSURLSessionUploadTask *uploadTask = [manager uploadTaskWithStreamedRequest:request progress:&progress completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
if (error) {
NSLog(#"Error: %#", error);
} else {
NSLog(#"%# %#", response, responseObject);
}
}];
[uploadTask resume];
and the crash result is this:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -streamStatus only defined for abstract class. Define -[AFMultipartBodyStream streamStatus]!'
* First throw call stack:
(
0 CoreFoundation 0x019d91e4 exceptionPreprocess + 180
1 libobjc.A.dylib 0x017588e5 objc_exception_throw + 44
2 CoreFoundation 0x019d8fbb +[NSException raise:format:] + 139
3 Foundation 0x01433b3b NSRequestConcreteImplementation + 218
4 Foundation 0x0143b746 -[NSStream(NSStream) streamStatus] + 48
5 readWritePlist 0x000333a1 -[AFMultipartBodyStream open] + 49
6 CoreFoundation 0x0199ac44 CFReadStreamOpen + 116
7 CFNetwork 0x026f395d _ZN30CoreReadStreamFromCFReadStream16_streamImpl_OpenEP13CFStreamErrorPh + 53
8 CFNetwork 0x027c5ae6 _ZThn60_N30CoreReadStreamFromCFReadStream16_streamImpl_OpenEP13CFStreamErrorPh + 34
9 CFNetwork 0x026d1112 _ZN14CoreStreamBase21_streamInterface_OpenEv + 72
10 CFNetwork 0x026f2c34 _ZN17HTTPNetConnection19prepareTransmissionEP17HTTPNetStreamInfoP17__CoreWriteStream + 1614
11 CFNetwork 0x026f2063 _ZN17HTTPNetConnection19requestStateChangedEPvN13NetConnection5StateEP13CFStreamError + 415
12 CFNetwork 0x026f21fd _ZN13NetConnection18scheduleNewRequestEP13_CFNetRequestS1_h + 293
13 CFNetwork 0x026f1da4 _ZN13NetConnection7enqueueEPvh + 538
14 CFNetwork 0x026f1b26 _ZN17HTTPNetStreamInfo16_streamImpl_OpenEP13CFStreamErrorPh + 104
15 CFNetwork 0x02756846 _ZThn60_N17HTTPNetStreamInfo16_streamImpl_OpenEP13CFStreamErrorPh + 34
16 CFNetwork 0x026d1112 _ZN14CoreStreamBase21_streamInterface_OpenEv + 72
17 CFNetwork 0x026f1315 _ZN12HTTPProtocol10openStreamEv + 267
18 CFNetwork 0x0276498c _ZN12HTTPProtocol26useNetConnectionForRequestEP13NetConnectionP15__CFHTTPMessageh + 1550
19 CFNetwork 0x026f05d8 _ZN24HTTPConnectionCacheEntry28dispatchConnectionToProtocolEP13NetConnectionP12HTTPProtocolP18HTTPRequestMessageh + 284
20 CFNetwork 0x026f03b9 _ZN24HTTPConnectionCacheEntry34notifyNextProtocolOfOpenConnectionEP13NetConnectionh + 349
21 CFNetwork 0x026ed71d _ZN24HTTPConnectionCacheEntry25enqueueRequestForProtocolEP12HTTPProtocolP15__CFHTTPMessage + 637
22 CFNetwork 0x026ed0db _ZN19HTTPConnectionCache34_onqueue_enqueueRequestForProtocolEP12HTTPProtocolP15__CFHTTPMessage + 185
23 CFNetwork 0x0276a897 ___ZN19HTTPConnectionCache25enqueueRequestForProtocolEP12HTTPProtocolP15__CFHTTPMessage_block_invoke + 35
24 CoreFoundation 0x0197ac69 CFArrayApplyFunction + 57
25 CFNetwork 0x026e8441 _ZN19RunloopBlockContext7performEv + 155
26 CFNetwork 0x027ca3f4 _ZThn16_N19RunloopBlockContext24multiplexerClientPerformEv + 20
27 CFNetwork 0x026e8257 _ZN17MultiplexerSource7performEv + 299
28 CFNetwork 0x026e806c _ZN17MultiplexerSource8_performEPv + 76
29 CoreFoundation 0x0196277f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 15
30 CoreFoundation 0x0196210b CFRunLoopDoSources0 + 235
31 CoreFoundation 0x0197f1ae __CFRunLoopRun + 910
32 CoreFoundation 0x0197e9d3 CFRunLoopRunSpecific + 467
33 CoreFoundation 0x0197e7eb CFRunLoopRunInMode + 123
34 Foundation 0x01353ece +[NSURLConnection(Loader) _resourceLoadLoop:] + 381
35 Foundation 0x013afa07 -[NSThread main] + 76
36 Foundation 0x013af966 __NSThread__main + 1275
37 libsystem_pthread.dylib 0x0241d5fb _pthread_body + 144
38 libsystem_pthread.dylib 0x0241d485 _pthread_struct_init + 0
39 libsystem_pthread.dylib 0x02422cf2 thread_start + 34
)
libc++abi.dylib: terminating with uncaught exception of type NSException
any idea what is my mistake here..!?
After I update AFNetwork to latest version which is 2.3.1, problem got solved.
Related
I'm trying to access some url (any URL) and it failed from iOS root process (running on Jailbroken device)
I Creating an application which running SockPuppet Exploit (iOS 12.0)
After exploitation, the app responsible to running another process on root privileges
The new process responsible to access url
On any URL I tried to, I'm getting a crash.
Here is my code:
NSURL *url = [NSURL URLWithString:#"https://jsonplaceholder.typicode.com/todos/1"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[url standardizedURL]];
[request setHTTPMethod:#"GET"];
[request setValue:#"application/x-www-form-urlencoded; charset=utf-8" forHTTPHeaderField:#"Content-Type"];
NSURLSessionDataTask *sessionPostDataTask = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (data == nil)
{
return;
}
NSLog(#"data: %#", data);
}];
[sessionPostDataTask resume];
Crash Info:
OS Version: iPhone OS 12.0 (16A366)
Baseband Version: 3.00.01
Report Version: 104
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Triggered by Thread: 1
Application Specific Information:
abort() called
Last Exception Backtrace:
0 CoreFoundation 0x220e4bef8 __exceptionPreprocess + 228
1 libobjc.A.dylib 0x220019a40 objc_exception_throw + 55
2 CoreFoundation 0x220dc185c _CFThrowFormattedException + 111
3 CoreFoundation 0x220d30e20 -[__NSArrayM insertObject:atIndex:] + 1211
4 Foundation 0x2217c6480 -[NSUserDefaults+ 25728 (NSUserDefaults) init] + 255
5 Foundation 0x2217c6338 +[NSUserDefaults+ 25400 (NSUserDefaults) standardUserDefaults] + 83
6 UIFoundation 0x22b45f8a0 attributeDictionaryHash + 367
7 Foundation 0x2218a7324 hashProbe + 71
8 Foundation 0x2217c4e34 -[NSConcreteHashTable getItem:] + 39
9 UIFoundation 0x22b40a868 +[NSAttributeDictionary newWithDictionary:] + 135
10 UIFoundation 0x22b45f678 +[NSAttributeDictionary initialize] + 899
11 libobjc.A.dylib 0x220015024 CALLING_SOME_+initialize_METHOD + 23
12 libobjc.A.dylib 0x22001af84 _class_initialize + 295
13 libobjc.A.dylib 0x2200248f8 lookUpImpOrForward + 279
14 libobjc.A.dylib 0x220031098 _objc_msgSend_uncached + 55
15 Foundation 0x2217eff0c -[NSConcreteMutableAttributedString replaceCharactersInRange:withString:] + 419
16 Foundation 0x22180caf8 -[NSConcreteMutableAttributedString initWithString:] + 267
17 liblog_network.dylib 0x24abb6bb8 NWOLCopyFormattedStringIPv4Address + 379
18 liblog_network.dylib 0x24abb6a20 OSLogCopyFormattedString + 195
19 libsystem_trace.dylib 0x220a7fac4 _os_log_fmt_compose_annotated + 703
20 libsystem_trace.dylib 0x220a7f250 os_log_fmt_compose + 883
21 libsystem_trace.dylib 0x220a84c0c _os_log_impl_flatten_and_send + 3163
22 libsystem_trace.dylib 0x220a868ec os_log_pack_compose + 83
23 libnetwork.dylib 0x221ff3b88 -[NWConcrete_nw_address_endpoint createDescription:] + 315
24 libnetwork.dylib 0x221ff5130 -[NWConcrete_nw_endpoint getDescription] + 83
25 libnetwork.dylib 0x221f809c8 nw_endpoint_resolver_update + 5511
26 libnetwork.dylib 0x221e8c020 __nw_resolver_update_client_block_invoke + 103
27 libdispatch.dylib 0x2208836c8 _dispatch_call_block_and_release + 23
28 libdispatch.dylib 0x220884484 _dispatch_client_callout + 15
29 libdispatch.dylib 0x22082db9c _dispatch_workloop_invoke$VARIANT$mp + 2311
30 libdispatch.dylib 0x220834f00 _dispatch_workloop_worker_thread + 599
31 libsystem_pthread.dylib 0x220a660f0 _pthread_wqthread + 311
32 libsystem_pthread.dylib 0x220a68d00 start_wqthread + 3
Thread 1 name: Dispatch queue: com.apple.network.connections
Thread 1 Crashed:
0 libsystem_kernel.dylib 0x00000002209e1104 __pthread_kill + 8
1 libsystem_pthread.dylib 0x0000000220a5c0e0 pthread_kill$VARIANT$mp + 380
2 libsystem_c.dylib 0x0000000220938d78 abort + 140
3 libc++abi.dylib 0x0000000220000f78 __cxa_bad_cast + 0
4 libc++abi.dylib 0x0000000220001120 default_unexpected_handler+ 8480 () + 0
5 libobjc.A.dylib 0x0000000220019e48 _objc_terminate+ 28232 () + 124
6 libc++abi.dylib 0x000000022000d0fc std::__terminate(void (*)+ 57596 ()) + 16
7 libc++abi.dylib 0x000000022000d188 std::terminate+ 57736 () + 84
8 libsystem_trace.dylib 0x0000000220a7fc54 _os_log_fmt_compose_annotated + 1104
9 libsystem_trace.dylib 0x0000000220a7f250 os_log_fmt_compose + 884
10 libsystem_trace.dylib 0x0000000220a84c0c _os_log_impl_flatten_and_send + 3164
11 libsystem_trace.dylib 0x0000000220a868ec os_log_pack_compose + 84
12 libnetwork.dylib 0x0000000221ff3b88 -[NWConcrete_nw_address_endpoint createDescription:] + 316
13 libnetwork.dylib 0x0000000221ff5130 -[NWConcrete_nw_endpoint getDescription] + 84
14 libnetwork.dylib 0x0000000221f809c8 nw_endpoint_resolver_update + 5512
15 libnetwork.dylib 0x0000000221e8c020 __nw_resolver_update_client_block_invoke + 104
16 libdispatch.dylib 0x00000002208836c8 _dispatch_call_block_and_release + 24
17 libdispatch.dylib 0x0000000220884484 _dispatch_client_callout + 16
18 libdispatch.dylib 0x000000022082db9c _dispatch_workloop_invoke$VARIANT$mp + 2312
19 libdispatch.dylib 0x0000000220834f00 _dispatch_workloop_worker_thread + 600
20 libsystem_pthread.dylib 0x0000000220a660f0 _pthread_wqthread + 312
21 libsystem_pthread.dylib 0x0000000220a68d00 start_wqthread + 4
I make a Facebook graph request like so, than I try to set a UIImageView From the result from the Facebook Graph Request.
NSString *path = [NSString stringWithFormat:#"http://graph.facebook.com/%#/picture?type=large", userID];
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:path
parameters:nil
HTTPMethod:#"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result,
NSError *error) {
cell.profilePicture.image = result;
}];
However the app crashes and gives me this error report?
2015-07-01 15:31:02.573 Hang[1916:45710] -[__NSCFDictionary size]: unrecognized selector sent to instance 0x7fb29a5658b0
2015-07-01 15:31:02.578 Hang[1916:45710] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary size]: unrecognized selector sent to instance 0x7fb29a5658b0'
*** First throw call stack:
(
0 CoreFoundation 0x000000010bc75c65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010b90ebb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010bc7d0ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010bbd313c ___forwarding___ + 988
4 CoreFoundation 0x000000010bbd2cd8 _CF_forwarding_prep_0 + 120
5 UIKit 0x000000010c1f178b -[UIImageView _updateImageViewForOldImage:newImage:] + 570
6 UIKit 0x000000010c1ee27e -[UIImageView setImage:] + 316
7 Hang 0x0000000109e3b540 __66-[CollectionViewController collectionView:cellForItemAtIndexPath:]_block_invoke + 160
8 Hang 0x0000000109e5e6ef -[FBSDKGraphRequestMetadata invokeCompletionHandlerForConnection:withResults:error:] + 146
9 Hang 0x0000000109e64a5d __64-[FBSDKGraphRequestConnection processResultBody:error:metadata:]_block_invoke370 + 142
10 Hang 0x0000000109e647f2 -[FBSDKGraphRequestConnection processResultBody:error:metadata:] + 1046
11 Hang 0x0000000109e642c0 __64-[FBSDKGraphRequestConnection completeWithResults:networkError:]_block_invoke + 428
12 CoreFoundation 0x000000010bbabf22 __53-[__NSArrayM enumerateObjectsWithOptions:usingBlock:]_block_invoke + 114
13 CoreFoundation 0x000000010bbab67c -[__NSArrayM enumerateObjectsWithOptions:usingBlock:] + 300
14 Hang 0x0000000109e64077 -[FBSDKGraphRequestConnection completeWithResults:networkError:] + 670
15 Hang 0x0000000109e63364 -[FBSDKGraphRequestConnection completeFBSDKURLConnectionWithResponse:data:networkError:] + 669
16 Hang 0x0000000109e61a92 __36-[FBSDKGraphRequestConnection start]_block_invoke_2 + 72
17 Hang 0x0000000109e5ee20 -[FBSDKURLConnection invokeHandler:error:response:responseData:] + 85
18 Hang 0x0000000109e5ed95 -[FBSDKURLConnection logAndInvokeHandler:response:responseData:] + 395
19 Hang 0x0000000109e5f0e6 -[FBSDKURLConnection connectionDidFinishLoading:] + 135
20 CFNetwork 0x000000010add10bc __65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke + 69
21 CFNetwork 0x000000010add1060 -[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 199
22 CFNetwork 0x000000010add11c7 -[NSURLConnectionInternal _withActiveConnectionAndDelegate:] + 48
23 CFNetwork 0x000000010aca0757 ___ZN27URLConnectionClient_Classic26_delegate_didFinishLoadingEU13block_pointerFvvE_block_invoke + 107
24 CFNetwork 0x000000010ad6dde1 ___ZN27URLConnectionClient_Classic18_withDelegateAsyncEPKcU13block_pointerFvP16_CFURLConnectionPK33CFURLConnectionClientCurrent_VMaxE_block_invoke_2 + 273
25 CFNetwork 0x000000010ac8ba26 _ZN19RunloopBlockContext13_invoke_blockEPKvPv + 72
26 CoreFoundation 0x000000010bb7c354 CFArrayApplyFunction + 68
27 CFNetwork 0x000000010ac8b8e7 _ZN19RunloopBlockContext7performEv + 133
28 CFNetwork 0x000000010ac8b726 _ZN17MultiplexerSource7performEv + 256
29 CFNetwork 0x000000010ac8b53c _ZN17MultiplexerSource8_performEPv + 72
30 CoreFoundation 0x000000010bba9431 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
31 CoreFoundation 0x000000010bb9f2fd __CFRunLoopDoSources0 + 269
32 CoreFoundation 0x000000010bb9e934 __CFRunLoopRun + 868
33 CoreFoundation 0x000000010bb9e366 CFRunLoopRunSpecific + 470
34 GraphicsServices 0x000000010d3c5a3e GSEventRunModal + 161
35 UIKit 0x000000010c06e900 UIApplicationMain + 1282
36 Hang 0x0000000109e39acf main + 111
37 libdyld.dylib 0x0000000110e59145 start + 1
38 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Why is this happening? How can I set my UIImageView from the Facebook Graph Request result.
try this code:
[[[FBSDKGraphRequest alloc] initWithGraphPath:#"me" parameters:#{#"fields": #"id, name, link, first_name, last_name, picture.type(large), email, birthday, bio ,location , friends ,hometown , friendlists"}]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error)
{
NSLog(#"result is:%#",result);
yourimageView.image = [UIImage imageWithContentsOfURL:[NSURL URLWithString:[[[result objectForKey:#"picture"] objectForKey:#"data"] objectForKey:#"url"]]];
}
else
{
NSLog(#"Error %#",error);
}
}];
I created a new project in xcode with only this code to test
NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
cachePath = [cachePath stringByAppendingPathComponent:#"blabla.jpg"];
NSString *fileURL = #"http://en.wikipedia.org/dcjhbdkcjc";
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:fileURL]];
AFDownloadRequestOperation *operation = [[AFDownloadRequestOperation alloc] initWithRequest:request targetPath:cachePath shouldResume:YES];
//AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(#"%#",responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(#"%#",error);
}];
[operation start];
And crashes when 404 is returned with the following error con console, none of the NSLog in the test code are ever called.
2014-08-22 16:51:33.809 AFDownloadTest[7106:3403] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[3]'
*** First throw call stack:
(
0 CoreFoundation 0x0000000101b39495 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010172d99e objc_exception_throw + 43
2 CoreFoundation 0x0000000101b02dce -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 382
3 CoreFoundation 0x0000000101b2e23f +[NSDictionary dictionaryWithObjects:forKeys:count:] + 63
4 AFDownloadTest 0x000000010002a955 -[AFHTTPResponseSerializer validateResponse:data:error:] + 1893
5 AFDownloadTest 0x0000000100002cf2 -[AFDownloadRequestOperation connection:didReceiveData:] + 178
6 Foundation 0x000000010141e36b __65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke + 48
7 Foundation 0x00000001012d1bdb -[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 210
8 Foundation 0x00000001012d1aec -[NSURLConnectionInternal _withActiveConnectionAndDelegate:] + 69
9 Foundation 0x00000001012d1e37 _NSURLConnectionDidReceiveData + 79
10 CFNetwork 0x0000000106ae8e05 ___ZN27URLConnectionClient_Classic23_delegate_cacheTrifectaEPK20_CFCachedURLResponseU13block_pointerFvvE_block_invoke + 778
11 CFNetwork 0x0000000106ae4802 ___ZN27URLConnectionClient_Classic18_withDelegateAsyncEPKcU13block_pointerFvP16_CFURLConnectionPK33CFURLConnectionClientCurrent_VMaxE_block_invoke_2 + 84
12 CoreFoundation 0x0000000101adff74 CFArrayApplyFunction + 68
13 CFNetwork 0x0000000106a573e7 _ZN19RunloopBlockContext7performEv + 133
14 CFNetwork 0x0000000106a57217 _ZN17MultiplexerSource7performEv + 247
15 CFNetwork 0x0000000106a5703a _ZN17MultiplexerSource8_performEPv + 72
16 CoreFoundation 0x0000000101ac8d21 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
17 CoreFoundation 0x0000000101ac85f2 __CFRunLoopDoSources0 + 242
18 CoreFoundation 0x0000000101ae446f __CFRunLoopRun + 767
19 CoreFoundation 0x0000000101ae3d83 CFRunLoopRunSpecific + 467
20 Foundation 0x0000000101339fce -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 253
21 Foundation 0x00000001012dfdc0 -[NSRunLoop(NSRunLoop) run] + 74
22 AFDownloadTest 0x0000000100011fe8 +[AFURLConnectionOperation networkRequestThreadEntryPoint:] + 280
23 Foundation 0x00000001013352df __NSThread__main__ + 1167
24 libsystem_pthread.dylib 0x000000010236e2fc _pthread_body + 131
25 libsystem_pthread.dylib 0x000000010236e279 _pthread_body + 0
26 libsystem_pthread.dylib 0x000000010236c4b1 thread_start + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Halting the app at the line 169 of the file AFURLConnectionOperation.m
which is [runLoop run];
This was a bug on the AFDownloadRequestOperation code, was fixed on this commit a36bd98208, on sept 4, 2014
I have parsed JSON in tableview and I want to implement search bar to filter huge data. I have tried implementing search bar from here.
but it crashes.
-(void)parsingmethod{
NSString *string = [NSString stringWithFormat:#"HEREISMYJSONURL"];
NSURL *url = [NSURL URLWithString:string];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.responseSerializer = [AFJSONResponseSerializer serializer];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
self.json=[responseObject valueForKey:#"name"];
self.filteredCandyArray = [NSMutableArray arrayWithCapacity:[candyArray count]];
self.filteredArray=[NSMutableArray arrayWithArray:self.json];
NSLog(#"self.flteredarray=%#",self.filteredArray);
self.current_address = [responseObject valueForKey:#"current_address"];
[self.tableView reloadData];
} failure:^(AFHTTPRequestOperation *operation, NSError *error){
NSLog(#"Oops, something went wrong: %#", [error localizedDescription]);
}];
[operation start];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if ( cell == nil ) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
if (tableView == self.searchDisplayController.searchResultsTableView) {
cell.textLabel.text =[self.filteredArray objectAtIndex:indexPath.row];
} else {
cell.textLabel.text =[self.json objectAtIndex:indexPath.row];
}
cell.detailTextLabel.text=[self.current_address objectAtIndex:indexPath.row];
return cell;
}
And content filtering and delegate method also done from here
Below my Crash Logs
***** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<__NSCFString 0xcc515f0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key name.'
*** First throw call stack:
(
0 CoreFoundation 0x021af1e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x0199c8e5 objc_exception_throw + 44
2 CoreFoundation 0x0223efe1 -[NSException raise] + 17
3 Foundation 0x0165cc7a -[NSObject(NSKeyValueCoding) valueForUndefinedKey:] + 282
4 Foundation 0x015c9dfd _NSGetUsingKeyValueGetter + 81
5 Foundation 0x015c9437 -[NSObject(NSKeyValueCoding) valueForKey:] + 260
6 Foundation 0x0159a465 -[NSFunctionExpression expressionValueWithObject:context:] + 1260
7 Foundation 0x016202c1 -[NSComparisonPredicate evaluateWithObject:substitutionVariables:] + 248
8 Foundation 0x016201c1 -[NSPredicate evaluateWithObject:] + 48
9 Foundation 0x01620141 _filterObjectsUsingPredicate + 418
10 Foundation 0x0161fefa -[NSArray(NSPredicateSupport) filteredArrayUsingPredicate:] + 328
11 LuckyHR 0x00043995 -[NameListTableViewController filterContentForSearchText:scope:] + 245
12 LuckyHR 0x00043bf2 -[NameListTableViewController searchDisplayController:shouldReloadTableForSearchString:] + 386
13 UIKit 0x00a1eb37 -[UISearchDisplayController searchBar:textDidChange:] + 128
14 UIKit 0x0093dc56 -[UISearchBar(UISearchBarStatic) _searchFieldEditingChanged] + 178
15 libobjc.A.dylib 0x019ae82b -[NSObject performSelector:withObject:] + 70
16 UIKit 0x0065e3b9 -[UIApplication sendAction:to:from:forEvent:] + 108
17 UIKit 0x0065e345 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
18 UIKit 0x0075fbd1 -[UIControl sendAction:to:forEvent:] + 66
19 UIKit 0x0075ffc6 -[UIControl _sendActionsForEvents:withEvent:] + 577
20 UIKit 0x00d8529d -[UITextField fieldEditorDidChange:] + 221
21 UIKit 0x00765db4 -[UIFieldEditor textInputDidChange:] + 58
22 UIKit 0x00d931b3 -[UITextInputController _sendDelegateChangeNotificationsForText:selection:] + 118
23 UIKit 0x00d95090 -[UITextInputController _insertText:fromKeyboard:] + 768
24 UIKit 0x00d95954 -[UITextInputController insertText:] + 372
25 UIKit 0x00768a64 -[UIFieldEditor insertText:] + 1086
26 UIKit 0x00d88ffa -[UITextField insertText:] + 59
27 UIKit 0x00848760 -[UIKeyboardImpl insertText:] + 87
28 UIKit 0x00859ea4 -[TIKeyboardOperationInsertText(UIKeyboardImpl) main] + 83
29 Foundation 0x01670c79 -[__NSOperationInternal _start:] + 671
30 Foundation 0x015ed9c8 -[NSOperation start] + 83
31 UIKit 0x00846d4d -[UIKeyboardImpl performOperations:] + 153
32 UIKit 0x00844f8e -[UIKeyboardImpl continueHandleKeyboardInputWithOperations:] + 75
33 UIKit 0x00844ddc __73-[UIKeyboardImpl replyHandlerForHandleKeyboardInputWithExecutionContext:]_block_invoke_2 + 44
34 UIKit 0x00dae978 -[UIKeyboardTaskQueue continueExecutionOnMainThread] + 402
35 libobjc.A.dylib 0x019ae82b -[NSObject performSelector:withObject:] + 70
36 Foundation 0x015f0e48 __NSThreadPerformPerform + 285
37 CoreFoundation 0x0213877f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
38 CoreFoundation 0x0213810b __CFRunLoopDoSources0 + 235
39 CoreFoundation 0x021551ae __CFRunLoopRun + 910
40 CoreFoundation 0x021549d3 CFRunLoopRunSpecific + 467
41 CoreFoundation 0x021547eb CFRunLoopRunInMode + 123
42 GraphicsServices 0x031d45ee GSEventRunModal + 192
43 GraphicsServices 0x031d442b GSEventRun + 104
44 UIKit 0x0065cf9b UIApplicationMain + 1225
45 LuckyHR 0x000499fd main + 141
46 libdyld.dylib 0x0392a70d start + 1
47 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) *
I went to similar questions posted here but still not figured it out.
It's clearly written :
3 Foundation 0x0165cc7a -[NSObject(NSKeyValueCoding) valueForUndefinedKey:] + 282
4 Foundation 0x015c9dfd _NSGetUsingKeyValueGetter + 81
5 Foundation 0x015c9437 -[NSObject(NSKeyValueCoding) valueForKey:] + 260
You ask for a key that doesn't exist so it's not working.
Crashlytics reported a crash in my app, and I have no idea of what is happening.
Here is the stacktrace:
Thread : Fatal Exception: NSInternalInconsistencyException
0 CoreFoundation 0x30080e83 __exceptionPreprocess + 130
1 libobjc.A.dylib 0x3a3dd6c7 objc_exception_throw + 38
2 CoreData 0x2fdcf941 -[NSSQLiteStatement cachedSQLiteStatement]
3 CoreData 0x2fdcf18d -[NSSQLiteConnection prepareSQLStatement:] + 52
4 CoreData 0x2fde8edf -[NSSQLChannel selectRowsWithCachedStatement:] + 58
5 CoreData 0x2fea8e1f newFetchedRowsForFetchPlan_MT + 910
6 CoreData 0x2fde8949 -[NSSQLCore fetchRowForObjectID:] + 1180
7 CoreData 0x2fde8311 -[NSSQLCore newValuesForObjectWithID:withContext:error:] + 256
8 CoreData 0x2fde762b _PFFaultHandlerLookupRow + 398
9 CoreData 0x2fde7193 _PF_FulfillDeferredFault + 218
10 CoreData 0x2fdf6449 _PF_ManagedObject_WillChangeValueForKeyIndex + 68
11 CoreData 0x2fdf636b _sharedIMPL_setvfk_core + 110
12 CoreData 0x2fe1995d _PF_Handler_Public_SetProperty + 92
13 CoreData 0x2fe1e2a9 -[NSManagedObject setValue:forKey:] + 124
14 Application 0x0004dc45 -[DateFormatter storeValue:error:] (DateFormatter.m:65)
15 Application 0x0004ee17 -[Formatter storeValue:inObject:] (Formatter.m:176)
16 Application 0x0002b5c5 -[NSManagedObject(App) setValuesForKeysWithReceivedDictionary:] (NSManagedObject+App.m:320)
17 Application 0x0002b8f3 -[NSManagedObject(App) setValuesForKeysWithReceivedDictionary:] (NSManagedObject+App.m:377)
18 Application 0x0006352d -[ODataGetOperation processResult:] (ODataGetOperation.m:220)
19 Application 0x0004420b -[ODataOperation connectionDidFinishLoading:] (ODataOperation.m:741)
20 Foundation 0x309bb47f __65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke + 54
21 Foundation 0x309bb3c1 -[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 204
22 Foundation 0x309bb2dd -[NSURLConnectionInternal _withActiveConnectionAndDelegate:] + 60
23 CFNetwork 0x2fceaf8f ___ZN27URLConnectionClient_Classic26_delegate_didFinishLoadingEU13block_pointerFvvE_block_invoke + 74
24 CFNetwork 0x2fce9b8f ___ZN27URLConnectionClient_Classic18_withDelegateAsyncEPKcU13block_pointerFvP16_CFURLConnectionPK33CFURLConnectionClientCurrent_VMaxE_block_invoke_2 + 54
25 CFNetwork 0x2fd1b337 ___ZNK17CoreSchedulingSet13_performAsyncEPKcU13block_pointerFvvE_block_invoke + 18
26 CoreFoundation 0x2ffb3ea1 CFArrayApplyFunction + 36
27 CFNetwork 0x2fc81e05 RunloopBlockContext::perform() + 164
28 CFNetwork 0x2fc81cd5 MultiplexerSource::perform() + 220
29 CFNetwork 0x2fc81b65 MultiplexerSource::_perform(void*) + 48
30 CoreFoundation 0x3004bf1f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
31 CoreFoundation 0x3004b3e7 __CFRunLoopDoSources0 + 206
32 CoreFoundation 0x30049bd7 __CFRunLoopRun + 630
33 CoreFoundation 0x2ffb4471 CFRunLoopRunSpecific + 524
34 CoreFoundation 0x2ffb4253 CFRunLoopRunInMode + 106
35 Foundation 0x309a2697 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 254
36 Application 0x00043b4b -[ODataOperation send] (ODataOperation.m:548)
37 Application 0x0004277f -[ODataOperation operationWillStartPreparingData] (ODataOperation.m:131)
38 Foundation 0x30a5396d __NSOQSchedule_f + 60
39 libdispatch.dylib 0x3a8c64b7 _dispatch_async_redirect_invoke + 110
40 libdispatch.dylib 0x3a8c77d9 _dispatch_root_queue_drain + 224
41 libdispatch.dylib 0x3a8c79c5 _dispatch_worker_thread2 + 56
42 libsystem_pthread.dylib 0x3a9f1dff _pthread_wqthread + 298
43 libsystem_pthread.dylib 0x3a9f1cc4 start_wqthread + 8
And there is the last method that calls setValue:forKey: in an NSManagedObject subclass
- (BOOL)storeValue:(void *)theValue error:(NSError **)theError
{
NSString * value = (__bridge NSString *)theValue;
NSString * errorMessage = nil;
if (![value length] && !isOptional)
errorMessage = [NSString stringWithFormat: NSLocalizedString(#"Value cannot be nil or empty (Date) for field %#", #""), varName];
else
{
NSDate * date = nil;
if ([value length])
{
date = [NSDate dateWithISO8601: value];
if (!date)
errorMessage = [NSString stringWithFormat: NSLocalizedString(#"Invalid date %# for field %#", #""), theValue, varName];
}
if (IvarAddress)
*((__strong NSDate **) IvarAddress) = date;
else
[currentObject setValue: date forKey: varName];
}
if (errorMessage)
{
if (theError)
*theError = [NSError errorWithDomain: AppDomain code: NSFormattingError userInfo: #{ NSLocalizedDescriptionKey: errorMessage }];
#ifdef DEBUG
NSLog(#"Formatter error: %#", errorMessage);
#endif
return NO;
}
return YES;
}
I am completely open to any suggestion :)
Update : The key exists, and the value being set is an NSDate so it's an attribute of the NSManagedObject, not a relationship.
Update 2 :
I also have another crash with that method (stack trace is not exactly the same) :
Thread : Fatal Exception: NSInternalInconsistencyException
0 CoreFoundation 0x30080e83 __exceptionPreprocess + 130
1 libobjc.A.dylib 0x3a3dd6c7 objc_exception_throw + 38
2 CoreData 0x2fddfacb -[NSSQLCore _obtainOpenChannel] + 234
3 CoreData 0x2fea8ded newFetchedRowsForFetchPlan_MT + 860
4 CoreData 0x2fde8949 -[NSSQLCore fetchRowForObjectID:] + 1180
5 CoreData 0x2fde8311 -[NSSQLCore newValuesForObjectWithID:withContext:error:] + 256
6 CoreData 0x2fde762b _PFFaultHandlerLookupRow + 398
7 CoreData 0x2fde7193 _PF_FulfillDeferredFault + 218
8 CoreData 0x2fdf6449 _PF_ManagedObject_WillChangeValueForKeyIndex + 68
9 CoreData 0x2fdf636b _sharedIMPL_setvfk_core + 110
10 CoreData 0x2fe1995d _PF_Handler_Public_SetProperty + 92
11 CoreData 0x2fe1e2a9 -[NSManagedObject setValue:forKey:] + 124
12 Application 0x000fcc45 -[DateFormatter storeValue:error:] (DateFormatter.m:65)
13 Application 0x000fde17 -[Formatter storeValue:inObject:] (Formatter.m:176)
14 Application 0x000da5c5 -[NSManagedObject(App) setValuesForKeysWithReceivedDictionary:] (NSManagedObject+.m:320)
15 Application 0x000da8f3 -[NSManagedObject(App) setValuesForKeysWithReceivedDictionary:] (NSManagedObject+.m:377)
16 Application 0x0011252d -[ODataGetOperation processResult:] (ODataGetOperation.m:220)
17 Application 0x000f320b -[ODataOperation connectionDidFinishLoading:] (ODataOperation.m:741)
18 Foundation 0x309bb47f __65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke + 54
19 Foundation 0x309bb3c1 -[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 204
20 Foundation 0x309bb2dd -[NSURLConnectionInternal _withActiveConnectionAndDelegate:] + 60
The exception message also is different :
_obtainOpenChannel -- NSSQLCore 0x15ef3780: no database channel is available
But I think they are two related issues.
So I finally found the reasons which were all related to multithreading/concurrency issues. Basically updating the same objects on two threads at the same time..
The recently added core data debug flags (-com.apple.CoreData.ConcurrencyDebug 1) were used to figure out what was happening.