sachinkesiraju / UberKit

An easy-to-use Objective-C wrapper for the Uber API (no longer supported)
MIT License
94 stars 22 forks source link

EXC_BAD_ACCESS Upon Logging in #7

Open joshim5 opened 9 years ago

joshim5 commented 9 years ago

Hello,

In UberKitDemo, I get an EXC_BAD_ACCESS after login:sender is called. This is after inserting the correct clientId, clientSecret, etc.

Perhaps this is an issue relating to the new API updates -- any thoughts?

It is clear to me that the issue occurs in [uberKit startLogin].

Best,

Joshua

sachinkesiraju commented 9 years ago

Hi @joshim5, I tried running the app and it worked just fine for me. Could you share some of your code, it's possible that you're calling an object that hasn't been initialized correctly. Also, have you tried adding breakpoints before the method call?

Sachin

joshim5 commented 9 years ago

Hi Sachin,

Thanks for the quick response. What redirect_uri are you using?

Best, Josh

hpogosyan commented 9 years ago

@joshim5 What should be used for the redirect_uri?

sachinkesiraju commented 9 years ago

@joshim5 @hpogosyan The redirect_uri according to the API documentation for a mobile app is supposed to go to your server that would have a special redirect back to your app. The redirect URL in the iOS app can be created by adding a URL type in the info section of your app's target as shown in the screenshot below. screen shot 2015-04-03 at 12 31 46 am The login flow would thus be: Login completion -> your own server (such as Heroku as Uber only accepts URIs as https) -> iOS app redirect URL (uberkit:// in this case)

Once you successfully login you should receive a callback to these delegate methods

- (void) uberKit: (UberKit *) uberKit didReceiveAccessToken: (NSString *) accessToken
{
    //Got the access token, can now make requests for user data
}
- (void) uberKit: (UberKit *) uberKit loginFailedWithError: (NSError *) error
{
    //An error occurred in the login process
}

This means that you can set any redirect URI you want in the dev portal as long as it redirects back to your app. So to answer your question, you just need to make sure that the redirect URI you're setting in UberKit is the same as the one you specify on the Uber developer portal and that your redirect URI calls your app's url type to re-enter.

Please let me know if you have any other questions regarding this.

-Sachin

hpogosyan commented 9 years ago

@sachinkesiraju I am using the UberKitDemo in your repo. What's the quickest way to setup a redirect_uri without actually hosting a server. Is there a service that does this?

sachinkesiraju commented 9 years ago

@hpogosyan To set up your own server, you could simply add an endpoint to one you already own or you could try using a service like Heroku or Paperplane.

hpogosyan commented 9 years ago

@sachinkesiraju I got around that issue, thank you for your help. Now I am experiencing a crash after a successful build:

http://hastebin.com/iqaheqoqod.md

I am on: Xcode Version 6.2 (6C131e) OS X Yosemite 10.10.2 iOS SDK 8.2

sachinkesiraju commented 9 years ago

@hpogosyan This a range exception which means that somewhere in your code, you are trying to access an element of an array that does not exist at the specified index. I believe this is the method where the error is

 [uberKit getProductsForLocation:location withCompletionHandler:^(NSArray *products, NSURLResponse *response, NSError *error)
     {
         if(!error)
         {
             UberProduct *product = [products objectAtIndex:0]; //Here's where the issue is
             NSLog(@"Product name of first %@", product.product_description);
         }
         else
         {
             NSLog(@"Error %@", error);
         }
     }];

Here, you're probably getting this error because you're trying to access index 0 of products when products may be empty. Try logging products to confirm this. This is merely a logical error and has nothing to do with an exc_bad_access or the login process.

alihen commented 9 years ago

I'm also experiencing this issue, although intermittent. EXC_BAD_ACCESS when calling [uberKit startLoginWithViewController:self] in the UberKit Demo

dserkin commented 9 years ago

Same for me. There is a random crash. It happens inside of web view:

1 0x30a671db in -[UIWebView webView:decidePolicyForNavigationAction:request:frame:decisionListener:]

You have to remove the delegate before leaving the view: // UberKit.m file

- (void)dealloc {
    [self.loginView setDelegate:nil];
}

more details here: http://stackoverflow.com/questions/1264727/uiwebview-exc-bad-access-crash

sachinkesiraju commented 9 years ago

Hey guys, Thank you so much for your feedback. I'm sorry I didn't have time to fix these bugs earlier, but I'm gonna get down to it now. There definitely seems to be an issue with the oauth flow so I'll be looking into it for the next couple of days. In case anyone's looking for an immediate solution, would everybody be cool if I replaced the login through web view with mobile safari (that worked in a previous commit)? Thanks so much for using UberKit. -Sachin

pxg commented 9 years ago

@dserkin that fix worked well for me. Thanks for your help.