0

I have a problem when try to sign in to Google Plus, my app crash after send my user and password when return to the app.

The error happens in this line:

BOOL openURL(id self, SEL _cmd, UIApplication* application, NSURL* url, NSString* sourceApplication, id annotation){
     [GPPURLHandler handleURL:url sourceApplication:@"com.google.chrome.ios" annotation:nil];
}
//...

I get in the device console:

: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Cannot create an NSPersistentStoreCoordinator with a nil model'

then using the url printed in the console I try:

NSURL *fixedURL = [NSURL URLWithString:@"com.domain.xxxxxx:/oauth2callback?state=75029341&code=4/hy789ysdfhfRA8cuIeHbO0fP3p1oXcFeCnYJe--vZgc.klaHKD1A8zws76f7678df6782M1BcwvNlQI&authuser=0&num_sessions=1&prompt=consent&session_state=dca3e8a678sdf678a6f7d880e02bcf5155e5822c038..5f88"];

[GPPURLHandler handleURL:fixedURL sourceApplication:@"com.google.chrome.ios" annotation:nil];
//...

with these code nothing happens

then I try:

 NSString *urlString =[NSMutableString stringWithFormat:@"%@:/oauth2callback?%@", [url scheme],[url query]];
 NSURL *fixedURL = [NSURL URLWithString:urlString];
//...

And get the first error.

in Property List Key

<key>CFBundleURLTypes</key>
   <array>
      <dict>
         <key>CFBundleURLName</key>
         <string>com.domain.xxxxxx</string>
         <key>CFBundleURLSchemes</key>
         <array>
            <string>com.domain.xxxxxx</string>
         </array>
         <key>CFBundleURLTypes</key>
         <string>Editor</string>
      </dict>
   </array>
   <key>GPGApplicationID</key>
   <string>123123123-0fnaerghgic4er3g9cmn045daasl0u1u.apps.googleusercontent.com</string>

What I do wrong?

esdebon
  • 2,460
  • 5
  • 26
  • 33

1 Answers1

0

I'm not sure why you're trying to fabricate parameters to this method or where you're trying to call it. Your UIApplicationDelegate has an @optional responder attached to it:

- (BOOL)application:(UIApplication *)application openURL:(NSURL*)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation

The use-case for GPPURLHandler is to be called here (it is called by the OS to your application when a registered URL scheme is activated). This goes into your UIApplicationDelegate implementation:

- (BOOL)application:(UIApplication *)application openURL:(NSURL*)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
  return [GPPURLHandler handleURL:url sourceApplication:sourceApplication annotation:annotation];
}
Ian MacDonald
  • 13,472
  • 2
  • 30
  • 51
  • I have an override openURL... my app is not a native iOS app, then I have not direct access to the UIApplicationDelegate . – esdebon Jan 14 '15 at 19:01
  • If you don't have access to the `UIApplicationDelegate`, then you will not be able to respond to the OS telling your application to `openURL:`......... – Ian MacDonald Jan 14 '15 at 19:02
  • I have "indirect access", I am overriding the openURL in the UIApplicationDelegate. – esdebon Jan 14 '15 at 19:05
  • I'm confused. `UIApplicationDelegate` is a `@protocol`. You do not *override* these functions; you *implement* them. In your implementation of the `UIApplicationDelegate`, use the code that I have posted above. – Ian MacDonald Jan 14 '15 at 19:12
  • I create a custom subclass of the existing delegate and override the delegate function openURL – esdebon Jan 14 '15 at 19:15
  • Great. So you have one. So implement it like I wrote above. If you have specific errors, please post them instead of saying "this isn't *exactly* like my project". – Ian MacDonald Jan 14 '15 at 19:16
  • The specific error is: "Cannot create an NSPersistentStoreCoordinator with a nil model" – esdebon Jan 14 '15 at 19:19
  • Did you use my code, or are you still passing `nil` as your `annotation`? – Ian MacDonald Jan 14 '15 at 19:21
  • Yes, [GPPURLHandler handleURL:url sourceApplication:sourceApplication annotation:annotation]; then try [GPPURLHandler handleURL:url sourceApplication:sourceApplication annotation:self]; the try [GPPURLHandler handleURL:url sourceApplication:sourceApplication annotation:nil]; – esdebon Jan 14 '15 at 19:23
  • the crash happens when the url have "/oauth2callback?" – esdebon Jan 14 '15 at 19:23