简体   繁体   中英

IOS Can't Set UIImage From Facebook Graph Request

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM