IOS Can't Set UIImage From Facebook Graph Request - ios

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);
}
}];

Related

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FBSDKProfilePictureView CGImage]:

declare in .h file for facebook sdk integration
#property (weak, nonatomic) IBOutlet FBSDKProfilePictureView *profilePicture;
in .m file declare that
self.profilePicture.profileID = [ result objectForKey:#"id"];
UIImage *img=self.profilePicture;
giving error that
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FBSDKProfilePictureView CGImage]: unrecognized selector sent to instance 0x7fdd5a5651e0'
*** First throw call stack:(
0 CoreFoundation 0x0000000106366a75 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000105ffabb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010636dd1d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00000001062c59dc ___forwarding___ + 988
4 CoreFoundation 0x00000001062c5578 _CF_forwarding_prep_0 + 120
5 UIKit 0x00000001048c5732 UIImagePNGRepresentation + 33
6 SmartCookieProgram 0x0000000103bd0770 __47-[LoginViewController loginViewFetchedUserInfo]_block_invoke + 2880
7 SmartCookieProgram 0x0000000103c0b903 -[FBSDKGraphRequestMetadata invokeCompletionHandlerForConnection:withResults:error:] + 146
8 SmartCookieProgram 0x0000000103c11c6d __64-[FBSDKGraphRequestConnection processResultBody:error:metadata:]_block_invoke370 + 142
9 SmartCookieProgram 0x0000000103c11a02 -[FBSDKGraphRequestConnection processResultBody:error:metadata:] + 1046
10 SmartCookieProgram 0x0000000103c114d0 __64-[FBSDKGraphRequestConnection completeWithResults:networkError:]_block_invoke + 428
11 CoreFoundation 0x000000010629e782 __53-[__NSArrayM enumerateObjectsWithOptions:usingBlock:]_block_invoke + 114
12 CoreFoundation 0x000000010629dedc -[__NSArrayM enumerateObjectsWithOptions:usingBlock:] + 300
13 SmartCookieProgram 0x0000000103c11287 -[FBSDKGraphRequestConnection completeWithResults:networkError:] + 670
14 SmartCookieProgram 0x0000000103c10574 -[FBSDKGraphRequestConnection completeFBSDKURLConnectionWithResponse:data:networkError:] + 669
15 SmartCookieProgram 0x0000000103c0eca2 __36-[FBSDKGraphRequestConnection start]_block_invoke_2 + 72
16 SmartCookieProgram 0x0000000103c0c034 -[FBSDKURLConnection invokeHandler:error:response:responseData:] + 85
17 SmartCookieProgram 0x0000000103c0bfa9 -[FBSDKURLConnection logAndInvokeHandler:response:responseData:] + 395
18 SmartCookieProgram 0x0000000103c0c2fa -[FBSDKURLConnection connectionDidFinishLoading:] + 135
19 CFNetwork 0x0000000108e3b98c __65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke + 69
20 CFNetwork 0x0000000108e3b930 -[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 199
21 CFNetwork 0x0000000108e3ba97 -[NSURLConnectionInternal _withActiveConnectionAndDelegate:] + 48
22 CFNetwork 0x0000000108d0b937 ___ZN27URLConnectionClient_Classic26_delegate_didFinishLoadingEU13block_pointerFvvE_block_invoke + 107
23 CFNetwork 0x0000000108dd8a31 ___ZN27URLConnectionClient_Classic18_withDelegateAsyncEPKcU13block_pointerFvP16_CFURLConnectionPK33CFURLConnectionClientCurrent_VMaxE_block_invoke_2 + 273
24 CFNetwork 0x0000000108cf6d16 _ZN19RunloopBlockContext13_invoke_blockEPKvPv + 72
25 CoreFoundation 0x000000010626eb44 CFArrayApplyFunction + 68
26 CFNetwork 0x0000000108cf6bd7 _ZN19RunloopBlockContext7performEv + 133
27 CFNetwork 0x0000000108cf6a16 _ZN17MultiplexerSource7performEv + 256
28 CFNetwork 0x0000000108cf682c _ZN17MultiplexerSource8_performEPv + 72
29 CoreFoundation 0x000000010629bc91 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
30 CoreFoundation 0x0000000106291b5d __CFRunLoopDoSources0 + 269
31 CoreFoundation 0x0000000106291194 __CFRunLoopRun + 868
32 CoreFoundation 0x0000000106290bc6 CFRunLoopRunSpecific + 470
33 GraphicsServices 0x0000000107e02a58 GSEventRunModal + 161
34 UIKit 0x0000000104892580 UIApplicationMain + 1282
35 SmartCookieProgram 0x0000000103bce9c3 main + 115
36 libdyld.dylib 0x0000000107648145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
please provide solution for the error and also want to know how to get user Location using FBSDKGraphRequest and FBSDKGraphRequestConnection
FBSDKProfilePictureView is kind of UIView class, not an Image.
Add an UIImageVIew on your xib or storyboard and create an IBOutlet of the same.
#property (weak, nonatomic) IBOutlet UIImageView *imageView;
Use the following code:
self.profilePicture = [[FBSDKProfilePictureView alloc] initWithFrame:_imageView.frame];
[_profilePicture setProfileID: result[#"id"]];
[self.view addSubview:_profilePicture];
It will work!!

JSON Thumbnail image in Custom Table View Cell

I really get tired of trying to fix this so I think I need some help. I am filling each Cells of my iOS from an API which I successfully parsed (Can retrieve simple things such as texts, or numbers with no problem)
But when I tried to set the images for the thumbnails I am having some errors.
This is my code:
NSString *imageUrl = [tempDictionary valueForKeyPath:#"files.url_thumb"];
NSURL *url = [NSURL URLWithString:imageUrl];
NSData *imageData = [NSData dataWithContentsOfURL:url];
UIImage *thumbNailImage = [UIImage imageWithData:imageData];
dispatch_async(dispatch_get_main_queue(), ^{
[cell.ThumbImage setImage:thumbNailImage];
});
and this are the nightmares in my console:
2015-04-08 13:14:26.450 WebTableView[4976:173380] -[__NSArrayI length]:
unrecognized selector sent to instance 0x79e18b90
2015-04-08 13:14:26.509 WebTableView[4976:173380] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI length]: unrecognized selector sent to instance 0x79e18b90'
*** First throw call stack:
(
0 CoreFoundation 0x036c9466 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x03352a97 objc_exception_throw + 44
2 CoreFoundation 0x036d12c5 -[NSObject(NSObject) doesNotRecognizeSelector:] + 277
3 CoreFoundation 0x03619bc7 ___forwarding___ + 1047
4 CoreFoundation 0x0361978e _CF_forwarding_prep_0 + 14
5 CoreFoundation 0x035836cf CFStringGetLength + 143
6 CoreFoundation 0x036a9c8d _CFURLCreateWithURLString + 77
7 CoreFoundation 0x035952d3 CFURLCreateWithString + 35
8 Foundation 0x02f17999 -[NSURL(NSURL) initWithString:relativeToURL:] + 371
9 Foundation 0x02f17807 +[NSURL(NSURL) URLWithString:relativeToURL:] + 80
10 Foundation 0x02f177b1 +[NSURL(NSURL) URLWithString:] + 48
11 WebTableView 0x00111a8b -[TableViewController tableView:cellForRowAtIndexPath:] + 571
12 UIKit 0x01c26c9c -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 473
13 UIKit 0x01c26d7e -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 77
14 UIKit 0x01c0054b -[UITableView _updateVisibleCellsNow:isRecursive:] + 3034
15 UIKit 0x01c1aeb1 -[UITableView layoutSubviews] + 222
16 UIKit 0x01b907b1 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 608
17 libobjc.A.dylib 0x03368771 -[NSObject performSelector:withObject:] + 70
18 QuartzCore 0x009421cf -[CALayer layoutSublayers] + 152
19 QuartzCore 0x00936055 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 397
20 QuartzCore 0x00935eb0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
21 QuartzCore 0x008941b6 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 284
22 QuartzCore 0x0089558a _ZN2CA11Transaction6commitEv + 392
23 QuartzCore 0x00895c56 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
24 CoreFoundation 0x035ec18e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
25 CoreFoundation 0x035ec0d0 __CFRunLoopDoObservers + 400
26 CoreFoundation 0x035e1b0a __CFRunLoopRun + 1226
27 CoreFoundation 0x035e137b CFRunLoopRunSpecific + 443
28 CoreFoundation 0x035e11ab CFRunLoopRunInMode + 123
29 GraphicsServices 0x04b3d2c1 GSEventRunModal + 192
30 GraphicsServices 0x04b3d0fe GSEventRun + 104
31 UIKit 0x01b049b6 UIApplicationMain + 1526
32 WebTableView 0x000dd6cd main + 141
33 libdyld.dylib 0x03e94ac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I think valueForKeyPath: returning an array of objects. Try logging imageUrl and check what you are getting.
If you are confident that there would be only one url then you can try this -
NSString *imageUrl = [[tempDictionary valueForKeyPath:#"files.url_thumb"] lastObject];
Else try something like this -
valueForKey:#"files"] valueForKey:#"url_thumb]

App crashes while loading image via URL iOS

My app is crashing when it come to following code that is present below:
[cell.imgViewItem setImageWithURL:imageURL placeholderImage:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
NSLog(#"Finished");
} usingActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
Below is the log trace:
2014-09-23 14:11:05.353 SmartSwipe[2834:60b] -[UIImageView sd_cancelImageLoadOperationWithKey:]: unrecognized selector sent to instance 0x79c56ce0
2014-09-23 14:11:05.502 SmartSwipe[2834:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImageView sd_cancelImageLoadOperationWithKey:]: unrecognized selector sent to instance 0x79c56ce0'
*** First throw call stack:
(
0 CoreFoundation 0x034031e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x031808e5 objc_exception_throw + 44
2 CoreFoundation 0x034a0243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x033f350b ___forwarding___ + 1019
4 CoreFoundation 0x033f30ee _CF_forwarding_prep_0 + 14
5 SmartSwipe 0x0011c1a8 -[UIImageView(WebCache) sd_cancelCurrentImageLoad] + 56
6 SmartSwipe 0x00119744 -[UIImageView(WebCache) sd_setImageWithURL:placeholderImage:options:progress:completed:] + 276
7 SmartSwipe 0x0009cc18 -[UIImageView(UIActivityIndicatorForSDWebImage) setImageWithURL:placeholderImage:options:progress:completed:usingActivityIndicatorStyle:] + 504
8 SmartSwipe 0x0009c875 -[UIImageView(UIActivityIndicatorForSDWebImage) setImageWithURL:placeholderImage:completed:usingActivityIndicatorStyle:] + 229
9 SmartSwipe 0x0003f994 -[QuickScanViewController collectionView:cellForItemAtIndexPath:] + 948
10 UIKit 0x02395b30 -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:] + 257
11 UIKit 0x02397775 -[UICollectionView _updateVisibleCellsNow:] + 4730
12 UIKit 0x0239b65f -[UICollectionView layoutSubviews] + 265
13 UIKit 0x01dbe964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
14 libobjc.A.dylib 0x0319282b -[NSObject performSelector:withObject:] + 70
15 QuartzCore 0x007a745a -[CALayer layoutSublayers] + 148
16 QuartzCore 0x0079b244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
17 QuartzCore 0x0079b0b0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
18 QuartzCore 0x007017fa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
19 QuartzCore 0x00702b85 _ZN2CA11Transaction6commitEv + 393
20 QuartzCore 0x00703258 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
21 CoreFoundation 0x033cb36e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
22 CoreFoundation 0x033cb2bf __CFRunLoopDoObservers + 399
23 CoreFoundation 0x033a9254 __CFRunLoopRun + 1076
24 CoreFoundation 0x033a89d3 CFRunLoopRunSpecific + 467
25 CoreFoundation 0x033a87eb CFRunLoopRunInMode + 123
26 GraphicsServices 0x03f345ee GSEventRunModal + 192
27 GraphicsServices 0x03f3442b GSEventRun + 104
28 UIKit 0x01d4ff9b UIApplicationMain + 1225
29 SmartSwipe 0x001105bd main + 141
30 libdyld.dylib 0x04ec5701 start + 1
31 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Please help me, I am struggling with it. Thanks in advance.
You have written a method sd_setImageWithURL which gets called, and that method calls sd_cancelCurrentImageLoad for an UIImageView* that doesn't support the call. Check you source code where you implement sd_cancelCurrentImageLoad and what it does.
Please add SDWebImage framework in you project.
You can do so by using cocoapods, use 'pod "SDWebImage"' in the pod file.

AFDownloadRequestOperation crashes on 404 response

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

uploading NSData using AFNetwork terminating my APP

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.

Resources