swift - ios google sign-in, How can I get user image url? -
i working on ios/swift google sign-in. made demo in github. demo project: https://github.com/tanggod/googlesignin.git
according google(https://developers.google.com/identity/sign-in/ios/api/interface_g_i_d_profile_data#a8e229bffe211894473058c4ba247553c), user image url can fetched this:
- (nsurl *) imageurlwithdimension: (nsuinteger) dimension
gets user's profile image url given dimension in pixels each side of square.
but, when try imageurlwithdimension(120), app crash. have been struggling on half day , still don't know why. can me. thank much.
func signin(signin: gidsignin!, didsigninforuser user: gidgoogleuser!, witherror error: nserror!) { print("=== uiviewcontroller sign in") if (error == nil) { // perform operations on signed in user here. let userid = user.userid // client-side use only! //let idtoken = user.authentication.idtoken // safe send server let name = user.profile.name let email = user.profile.email if user.profile.hasimage{ // crash here !!!!!!!! cannot imageurl here, why? // let imageurl = user.profile.imageurlwithdimension(120) let imageurl = signin.currentuser.profile.imageurlwithdimension(120) print(" image url: ", imageurl.absolutestring) } // ... print(" userid: ", userid) // print(" idtoken: ", idtoken) print(" name: ", name) print(" email: ", email) labelname.text = name labelemail.text = email } else { print("\(error.localizeddescription)") } } the crash data follows:
2015-09-30 18:54:46.662 googlelogin[96614:] <gmr/info> app measurement v.1100000 started 2015-09-30 18:54:46.675 googlelogin[96614:5594982] configured [signin]. 2015-09-30 18:54:46.675 googlelogin[96614:5594982] failed configure []. 2015-09-30 18:54:46.676 googlelogin[96614:5594982] subspecs not present, not configured [analytics, admob, appinvite, cloudmessaging, maps]. 2015-09-30 18:54:46.676 googlelogin[96614:5594982] subspecs expected present [signin, measurement]. 2015-09-30 18:54:46.706 googlelogin[96614:] <gmr/info> network status has changed. code, status: 2, connected === uiviewcontroller sign in 2015-09-30 18:54:49.335 googlelogin[96614:5594982] -[nsurl isfifeurl]: unrecognized selector sent instance 0x7fe248c335c0 2015-09-30 18:56:46.968 googlelogin[96614:5594982] -[nsurl isfifeurl]: unrecognized selector sent instance 0x7fe248f11f20 2015-09-30 18:56:46.973 googlelogin[96614:5594982] *** terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[nsurl isfifeurl]: unrecognized selector sent instance 0x7fe248f11f20' *** first throw call stack: ( 0 corefoundation 0x0000000102304f65 __exceptionpreprocess + 165 1 libobjc.a.dylib 0x0000000104927deb objc_exception_throw + 48 2 corefoundation 0x000000010230d58d -[nsobject(nsobject) doesnotrecognizeselector:] + 205 3 corefoundation 0x000000010225af7a ___forwarding___ + 970 4 corefoundation 0x000000010225ab28 _cf_forwarding_prep_0 + 120 5 googlelogin 0x0000000101db6214 -[gidprofiledata imageurlwithdimension:] + 75 6 googlelogin 0x0000000101d29d0d _tfc11googlelogin14viewcontroller6signinfs0_ftgsqcso9gidsignin_16didsigninforusergsqcso13gidgoogleuser_9witherrorgsqcso7nserror__t_ + 2541 7 googlelogin 0x0000000101d2aa98 _ttofc11googlelogin14viewcontroller6signinfs0_ftgsqcso9gidsignin_16didsigninforusergsqcso13gidgoogleuser_9witherrorgsqcso7nserror__t_ + 88 8 googlelogin 0x0000000101dbdeb8 __37-[gidsignin addcalldelegatecallback:]_block_invoke + 123 9 googlelogin 0x0000000101db5ab6 -[gidcallbackqueue fire] + 147 10 googlelogin 0x0000000101dbdacb __38-[gidsignin adddecodeidtokencallback:]_block_invoke_2 + 385 11 libdispatch.dylib 0x00000001053eaef9 _dispatch_call_block_and_release + 12 12 libdispatch.dylib 0x000000010540b49b _dispatch_client_callout + 8 13 libdispatch.dylib 0x00000001053f334b _dispatch_main_queue_callback_4cf + 1738 14 corefoundation 0x00000001022653e9 __cfrunloop_is_servicing_the_main_dispatch_queue__ + 9 15 corefoundation 0x0000000102226939 __cfrunlooprun + 2073 16 corefoundation 0x0000000102225e98 cfrunlooprunspecific + 488 17 graphicsservices 0x00000001066b5ad2 gseventrunmodal + 161 18 uikit 0x00000001034b0676 uiapplicationmain + 171 19 googlelogin 0x0000000101d2c36d main + 109 20 libdyld.dylib 0x000000010543f92d start + 1 ) libc++abi.dylib: terminating uncaught exception of type nsexception (lldb) and says signin.currentuser.profile.imageurlwithdimension(120) invalid expression: 
exactly @ajmccall said, typo error!
but may workaround category nsurl.
new objective-c class:
nsurl+file.h
#import <foundation/foundation.h> @interface nsurl (file) - (bool) isfifeurl; @end nsurl+file.m
import "nsurl+file.h"
@implementation nsurl (file) - (bool) isfifeurl { return [self isfileurl]; } @end
Comments
Post a Comment