[iOS] Custom URL scheme: App crashes when started via URL scheme

2,211 views
Skip to first unread message

mobweb

unread,
Dec 26, 2011, 8:13:51 AM12/26/11
to phonegap
Hello all,

I'm trying to set up a custom URL scheme for my app using Phonegap
1.2. As far as I understand this[1] blog post, I won't have to change
anything the Phonegap code and only need to add a custom URL type in
my App-Name-Info.plist, which I did:

http://minus.com/m5frhpGtM#1

Using the simulator, it works just fine when my app is already
running. I start the app, push the home button, open up Safari and
type in my custom URL scheme: mailtemplates://1, and the corresponding
JavaScript gets called.

However, when my app isn't already running in the background, and I
try to launch it by opening Safari and typing in my custom URL scheme,
the app will start to launch, but after about a second the simulator
closes and the focus goes to XCode where the following message
appears:

http://minus.com/mmcRwKWea#1

Does anybody know what's going on here? As I said I haven't changed
anything in Phonegap's core files!

Thanks in advance!

[1]: http://blogs.nitobi.com/jesse/2011/03/07/supporting-custom-urls-in-phonegap-iphone-apps-pt-2-of-2/

mobweb

unread,
Dec 27, 2011, 7:53:22 AM12/27/11
to phonegap
Has anybody gotten custom URLs to work in the current stable release?
Seems like it's broken? I will have to re-install XCode anyway, maybe
that will solve the problem!
> [1]:http://blogs.nitobi.com/jesse/2011/03/07/supporting-custom-urls-in-ph...

mobweb

unread,
Jan 1, 2012, 2:57:39 PM1/1/12
to phonegap
So I reinstalled XCode, the SDK and updated PhoneGap to 1.3.0. The
error still occurs. When my app is already running in the background
and I call my custom URL scheme, it works perfectly. But if my app
isn't running and I enter my custom URL scheme, my app starts but is
frozen at the launch image. If I press the home button, the view
becomes black and I can't fix it unless I lock and then unlock the
phone. I will try to see if this behavior also occurs on a newly
created and empty PhoneGap project and file a bug report if it does.

Shazron

unread,
Jan 31, 2012, 3:27:38 PM1/31/12
to phon...@googlegroups.com
Any updates on this? It looks like a ui lock is happening - this is
usually when you try to instantiate an interactive element like an
alert through JavaScript when the app is starting up. wrapping the
call in a setTimeout with a 0 ms delay would fix this.

See:
https://github.com/apache/incubator-cordova-ios/blob/master/PhoneGapLib/Classes/PGPlugin.m#L158

> --
> You received this message because you are subscribed to the Google
> Groups "phonegap" group.
> To post to this group, send email to phon...@googlegroups.com
> To unsubscribe from this group, send email to
> phonegap+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/phonegap?hl=en?hl=en
>
> For more info on PhoneGap or to download the code go to www.phonegap.com

mobweb

unread,
Feb 1, 2012, 3:26:41 PM2/1/12
to phonegap
Thanks for the hint Shazron. Coincidentally just one day after your
response I finally found time to work on this again. :)

About your fix: How exactly would I implement that? I already tried
the following in my JS:

function handleOpenURL( string ) {
setTimeout( myFollowUpFunction, 5000, string );
}

And it still crashes. As for the code in your link: I have looked
around my AppDelegate.m file but I couldn't find out how to add a
timeout/delay there? Or is the file you linked to an update that I
should implement in my PhoneGap project?

I have some more info on the crash that occurs:

XCode points to the following line after the crash:

int retVal = UIApplicationMain(argc, argv, nil, @"AppDelegate");

Which is in a file named main.m. The error is simply "Thread 1:
Stopped after step".

On Jan 31, 9:27 pm, Shazron <shaz...@gmail.com> wrote:
> Any updates on this? It looks like a ui lock is happening - this is
> usually when you try to instantiate an interactive element like an
> alert through JavaScript when the app is starting up. wrapping the
> call in a setTimeout with a 0 ms delay would fix this.
>
> See:https://github.com/apache/incubator-cordova-ios/blob/master/PhoneGapL...

Shazron

unread,
Feb 2, 2012, 2:02:31 PM2/2/12
to phon...@googlegroups.com
No, the timeout delay is a wrapper around any JavaScript you call from
Obj-C to the UIWebView JS, like the link I showed you. in your
handleOpenURL function in JS, do not call any interactive elements. In
this case, the call to handleOpenURL should be wrapped in a
setTimeout, in Obj-C

mobweb

unread,
Feb 3, 2012, 3:26:12 AM2/3/12
to phonegap
Shazron, thanks again for your help. However I am not yet quite able
to get it to work. I am not sure how to merge this line (from the link
you posted):

---
return [self writeJavascript:[NSString
stringWithFormat:@"setTimeout(function() { %@; }, 0);", [pluginResult
toErrorCallbackString:callbackId]]];
---

Into this function (from my AppDelegate.m):

---
// this happens while we are running ( in the background, or from
within our own app )
// only valid if MailTemplates.plist specifies a protocol to handle
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL
*)url
{
    // must call super so all plugins will get the notification, and
their handlers will be called
// super also calls into javascript global function 'handleOpenURL'
    return [super application:application handleOpenURL:url];
}
---

However, from reading this[1] blog post by Jesse and also by the
inline comments, I get the feeling that if the app is already running
in the background, the function from my AppDelegate.m that posted
above is not used, but instead the following code is used, also
directly from my AppDelegate.m:

---
/**
 * This is main kick off after the app inits, the views and Settings
are setup here. (preferred - iOS4 and up)
 */
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    NSURL* url = [launchOptions
objectForKey:UIApplicationLaunchOptionsURLKey];
    if (url && [url isKindOfClass:[NSURL class]])
    {
        self.invokeString = [url absoluteString];
NSLog(@"MailTemplates launchOptions = %@",url);
    }

return [super application:application
didFinishLaunchingWithOptions:launchOptions];
}
---

I suppose after launching with a custom URL, this function would pass
a global "invokeString" variable to my JavaScript? But I was unable to
look into it further since every time I start my app with a custom
URL, it crashes when loading. Any idea how I might implement a timeout
in this function?

[1]: http://blogs.nitobi.com/jesse/2011/03/07/supporting-custom-urls-in-phonegap-iphone-apps-pt-1-of-2/

mobweb

unread,
Feb 17, 2012, 12:03:36 PM2/17/12
to phonegap
Still haven't been able to get this to work. Has anybody successfully
implemented a custom URL scheme into their iOS app?
> [1]:http://blogs.nitobi.com/jesse/2011/03/07/supporting-custom-urls-in-ph...

mobweb

unread,
Mar 15, 2012, 5:58:07 AM3/15/12
to phonegap
Haven't been able to fix this yet. I suppose I will just remove this
feature from my app for now.

Kerri Shotts

unread,
Mar 15, 2012, 12:53:16 PM3/15/12
to phon...@googlegroups.com
Any output to the console or logs? Those might help in tracking the problem down.
> > > >> > phonegap+unsubscribe@googlegroups.com
> > > >> > For more options, visit this group at
> > > >> >http://groups.google.com/group/phonegap?hl=en?hl=en
>
> > > >> > For more info on PhoneGap or to download the code go towww.phonegap.com
>
> > > > --
> > > > You received this message because you are subscribed to the Google
> > > > Groups "phonegap" group.
> > > > To post to this group, send email to phon...@googlegroups.com
> > > > To unsubscribe from this group, send email to
> > > > phonegap+unsubscribe@googlegroups.com

mobweb

unread,
Mar 22, 2012, 7:26:02 AM3/22/12
to phon...@googlegroups.com
This is the error that pops up, and the app freezes:



This only happens when the app is started that way. If it's already running (in the background), the custom URL is invoked just fine and all parameters are successfully passed to the app.

Shazron

unread,
Mar 24, 2012, 3:27:52 PM3/24/12
to phon...@googlegroups.com
@mobweb didn't mean to ignore this post - things get lost in the shuffle. Hang/crash issues are top priority and should be filed here
http://issues.apache.org/jira/browse/CB - this way you can get
notified of updates, and this issue won't be lost.

If you can file that issue, that will be great. That way we can
schedule the fix in an upcoming release.

Shaz

Mike

unread,
Aug 22, 2012, 12:34:33 PM8/22/12
to phon...@googlegroups.com
I'm having the exact same problem with Cordova 2.0.  I have an older PG 1.2 project that the custom URL scheme works fine for, but my 2.0 project crashes whenever I launch it from the custom URL scheme.
Shaz

> > > >> > phonegap+u...@googlegroups.com
> > > >> > For more options, visit this group at
> > > >> >http://groups.google.com/group/phonegap?hl=en?hl=en
>
> > > >> > For more info on PhoneGap or to download the code go towww.phonegap.com
>
> > > > --
> > > > You received this message because you are subscribed to the Google
> > > > Groups "phonegap" group.
> > > > To post to this group, send email to phon...@googlegroups.com
> > > > To unsubscribe from this group, send email to
> > > > phonegap+u...@googlegroups.com
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/phonegap?hl=en?hl=en
>
> > > > For more info on PhoneGap or to download the code go towww.phonegap.com

Mike

unread,
Aug 22, 2012, 2:49:57 PM8/22/12
to phon...@googlegroups.com
I think I have narrowed this down to being caused by the new Urban Airship plugin.  Without it, everything works fine.  With it, the app crashes on launch from a custom URL scheme.

Shazron

unread,
Aug 22, 2012, 5:09:55 PM8/22/12
to phon...@googlegroups.com
Crash log? Thanks.

--
-- You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en
 
For more info on PhoneGap or to download the code go to www.phonegap.com
 
To compile in the cloud, check out build.phonegap.com
 
 

Message has been deleted

Mike

unread,
Aug 23, 2012, 12:24:12 PM8/23/12
to phon...@googlegroups.com
Attached.
crashlog.txt

Shazron

unread,
Aug 23, 2012, 3:46:17 PM8/23/12
to phon...@googlegroups.com
Doesn't tell me anything (need to symbolicate). Try debugging this
yourself, by following these steps:
http://stackoverflow.com/a/6451601

It's for push notifications, but debugging custom urls is a similar
process. Once you Run, launch your app by entering the custom url in
Mobile Safari,

Mike

unread,
Aug 23, 2012, 4:58:20 PM8/23/12
to phon...@googlegroups.com
Thanks for the tip.

The app crashes at line 32 of main.m:

int retVal = UIApplicationMain(argc, argv, nil, @"AppDelegate");

I can provide whatever info you need using that technique, but I'm not the best with Xcode so if you can guide me, that would help.

Shazron

unread,
Aug 23, 2012, 5:14:33 PM8/23/12
to phon...@googlegroups.com
In the gdb window when it crashes, type "bt" then press Enter

Mike

unread,
Aug 23, 2012, 5:23:04 PM8/23/12
to phon...@googlegroups.com
* thread #1: tid = 0x1b03, 0x3622332c libsystem_kernel.dylib`__pthread_kill + 8, stop reason = signal SIGABRT
    frame #0: 0x3622332c libsystem_kernel.dylib`__pthread_kill + 8
    frame #1: 0x32d6f20e libsystem_c.dylib`pthread_kill + 54
    frame #2: 0x32d6829e libsystem_c.dylib`abort + 94
    frame #3: 0x35d25f6a libc++abi.dylib`abort_message + 46
    frame #4: 0x35d2334c libc++abi.dylib`_ZL17default_terminatev + 24
    frame #5: 0x37d14356 libobjc.A.dylib`_objc_terminate + 146
    frame #6: 0x35d233c4 libc++abi.dylib`_ZL19safe_handler_callerPFvvE + 76
    frame #7: 0x35d23450 libc++abi.dylib`std::terminate() + 20
    frame #8: 0x35d24824 libc++abi.dylib`__cxa_rethrow + 88
    frame #9: 0x37d142a8 libobjc.A.dylib`objc_exception_rethrow + 12
    frame #10: 0x358c350c CoreFoundation`CFRunLoopRunSpecific + 404
    frame #11: 0x358c336c CoreFoundation`CFRunLoopRunInMode + 104
    frame #12: 0x333d286a UIKit`-[UIApplication _run] + 550
    frame #13: 0x333cfcd4 UIKit`UIApplicationMain + 1080
    frame #14: 0x0007e9de PrizeReel`main + 66 at main.m:32

Shazron

unread,
Aug 23, 2012, 5:32:47 PM8/23/12
to phon...@googlegroups.com

Mike

unread,
Aug 23, 2012, 5:49:06 PM8/23/12
to phon...@googlegroups.com
* thread #1: tid = 0x1b03, 0x37d14238 libobjc.A.dylib`objc_exception_throw, stop reason = breakpoint 1.1
    frame #0: 0x37d14238 libobjc.A.dylib`objc_exception_throw
    frame #1: 0x35970a9a CoreFoundation`-[NSObject doesNotRecognizeSelector:] + 174
    frame #2: 0x3596f914 CoreFoundation`___forwarding___ + 300
    frame #3: 0x358ca650 CoreFoundation`_CF_forwarding_prep_0 + 48
    frame #4: 0x33551506 UIKit`-[UIApplication _applicationOpenURL:payload:] + 270
    frame #5: 0x33551506 UIKit`-[UIApplication _applicationOpenURL:payload:] + 270
    frame #6: 0x333d9f14 UIKit`-[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1800
    frame #7: 0x333d37dc UIKit`-[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 408
    frame #8: 0x333a1ac2 UIKit`-[UIApplication handleEvent:withNewEvent:] + 1010
    frame #9: 0x333a1566 UIKit`-[UIApplication sendEvent:] + 54
    frame #10: 0x333a0f3a UIKit`_UIApplicationHandleEvent + 5826
    frame #11: 0x3756022a GraphicsServices`PurpleEventCallback + 882
    frame #12: 0x35941522 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 38
    frame #13: 0x359414c4 CoreFoundation`__CFRunLoopDoSource1 + 140
    frame #14: 0x35940312 CoreFoundation`__CFRunLoopRun + 1370
    frame #15: 0x358c34a4 CoreFoundation`CFRunLoopRunSpecific + 300
    frame #16: 0x358c336c CoreFoundation`CFRunLoopRunInMode + 104
    frame #17: 0x333d286a UIKit`-[UIApplication _run] + 550
    frame #18: 0x333cfcd4 UIKit`UIApplicationMain + 1080
    frame #19: 0x0005b9de PrizeReel`main + 66 at main.m:32

Geri

unread,
Aug 27, 2012, 7:49:13 AM8/27/12
to phon...@googlegroups.com
I'm having the same issue, using Cordova 1.7.
I remember it was working for me in earlier versions, can say exactly when.

Shazron

unread,
Aug 27, 2012, 4:41:12 PM8/27/12
to phon...@googlegroups.com

Mike

unread,
Aug 27, 2012, 6:12:01 PM8/27/12
to phon...@googlegroups.com
* thread #1: tid = 0x1b03, 0x35d5032c libsystem_kernel.dylib`__pthread_kill + 8, stop reason = signal SIGABRT
    frame #0: 0x35d5032c libsystem_kernel.dylib`__pthread_kill + 8
    frame #1: 0x3289c20e libsystem_c.dylib`pthread_kill + 54
    frame #2: 0x3289529e libsystem_c.dylib`abort + 94
    frame #3: 0x35852f6a libc++abi.dylib`abort_message + 46
    frame #4: 0x3585034c libc++abi.dylib`_ZL17default_terminatev + 24
    frame #5: 0x37841356 libobjc.A.dylib`_objc_terminate + 146
    frame #6: 0x358503c4 libc++abi.dylib`_ZL19safe_handler_callerPFvvE + 76
    frame #7: 0x35850450 libc++abi.dylib`std::terminate() + 20
    frame #8: 0x35851824 libc++abi.dylib`__cxa_rethrow + 88
    frame #9: 0x378412a8 libobjc.A.dylib`objc_exception_rethrow + 12
    frame #10: 0x353f050c CoreFoundation`CFRunLoopRunSpecific + 404
    frame #11: 0x353f036c CoreFoundation`CFRunLoopRunInMode + 104
    frame #12: 0x32eff86a UIKit`-[UIApplication _run] + 550
    frame #13: 0x32efccd4 UIKit`UIApplicationMain + 1080
    frame #14: 0x000789de PrizeReel`main + 66 at main.m:32

Shazron

unread,
Aug 29, 2012, 3:37:37 AM8/29/12
to phon...@googlegroups.com
Yes, it would appear that their AppDelegate does not implement the
selector, just add it:
http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIApplicationDelegate_Protocol/Reference/Reference.html

Here's what comes with Cordova:
https://github.com/apache/incubator-cordova-ios/blob/master/bin/templates/project/__TESTING__/Classes/AppDelegate.m#L112-126


On Tue, Aug 28, 2012 at 7:48 PM, vishpool <vish...@gmail.com> wrote:
> [Re-posting since I can't see my first one]
>
> I am running into the same issues with UA Plugin with Cordova 2.0:
>
> 2012-08-28 22:28:16.409 MakeYou[16357:c07] -[UAAppDelegateSurrogate
> application:handleOpenURL:]: unrecognized selector sent to instance
> 0x8c02680
>
> 2012-08-28 22:28:16.411 MakeYou[16357:c07] *** Terminating app due to
> uncaught exception 'NSInvalidArgumentException', reason:
> '-[UAAppDelegateSurrogate application:handleOpenURL:]: unrecognized selector
> sent to instance 0x8c02680'
>
> *** First throw call stack:
>
> (0x42e022 0x26edcd6 0x42fcbd 0x394ed0 0x394cb2 0x5cb8c6 0x5d2329 0x5d2ae3
> 0x5d32fd 0x5d3c38 0x5c7634 0x2cfaef5 0x402195 0x366ff2 0x3658da 0x364d84
> 0x364c9b 0x2cf97d8 0x2cf988a 0x5c5626 0x2e86 0x2df5)
>
> terminate called throwing an exception
>
> Docs on the plugin:
> https://docs.urbanairship.com/display/DOCS/Client%3A+PhoneGap%3A+iOS+Plugin
>
> Could this be because UAAppDelegateSurrogate's missing
> application:handleOpenURL:?

Geri

unread,
Aug 29, 2012, 9:28:06 AM8/29/12
to phon...@googlegroups.com
In Cordova 2.0 I'm getting:

2012-08-29 16:26:41.828 @View[14721:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSCFConstantString stringByAppendingString:]: nil argument'

*** First throw call stack:

(0x35a8f88f 0x336b3259 0x35a8f789 0x35a8f7ab 0x34e20111 0x3b4f 0x38ab 0x3333f507 0x3326bc45 0x3326b4e5 0x3318fb03 0x3318f567 0x3318ef3b 0x3378122b 0x35a63523 0x35a634c5 0x35a62313 0x359e54a5 0x359e536d 0x33780439 0x331bdcd5 0x2fbf 0x2a74)

terminate called throwing an exception(lldb) 

vishpool

unread,
Aug 29, 2012, 11:46:06 AM8/29/12
to phon...@googlegroups.com
Shazron, 

I am not fully versed in Objective C or Native code quite yet. Could you help identify what exact code might suffice in UAAppDelegateSurrogate? I am not clear what to substitue for: self.viewController.webView, assuming that I should be following what's in AppDelegate.m from Cordova.

I am wondering if there's a way to fallback to AppDelegate.m itself, as UA really doesn't have any business with this logic. That is, my app is noticing this crash during Facebook login, authorize, and return to app flow. 

Shazron

unread,
Aug 29, 2012, 1:31:06 PM8/29/12
to phon...@googlegroups.com
Check out their sample how they do it:
https://github.com/urbanairship/phonegap-ua-push

Michael Gartner

unread,
Aug 29, 2012, 1:45:49 PM8/29/12
to phon...@googlegroups.com
I'm not sure I understand the procedure of what to add to fix this either. 

vishpool

unread,
Aug 30, 2012, 11:41:13 AM8/30/12
to phon...@googlegroups.com
The sample def. seems to work within it's scope, but would need to better support other handleOpenUrl use-cases. We have an open issue for UA on Github, but still no response: https://github.com/urbanairship/phonegap-ua-push/issues/3

 I am trying to see if I can get the older version ported over to 2.0 standards in the meanwhile: https://github.com/urbanairship/ios-phonegap-plugin ... any pointers?
Reply all
Reply to author
Forward
0 new messages