3

I followed http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html instruction to open app1(GlassButton) within app2(FontTest).

The open method of FontTest as following:

-(void)open {

  BOOL res = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"glassbutton://"]];

  if (res) {

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"glassbutton://"]];

  }

}

The value of "res" is "YES", but nothing happen after openURL method be called. The info-list of "FontTest"as following:

URL Schemes: glassbutton

URL identifier: com.yourcompany.glassbutton

I tried to open twitter and facebook apps by "twitter://" and "fb://" successfully. But I do not know why I cannot open this small app. I'm not sure whether any thing/step wrong or missing? Need I handle - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url for FontTest, if yes, how to handle it? Could you please kindly help me? Thanks in advance!

Cœur
  • 37,241
  • 25
  • 195
  • 267
mobguang
  • 245
  • 2
  • 4
  • 15

1 Answers1

3

To request the launch of your app use something like this:

NSString *urlString= @"glassbutton://com.yourcompany.glassbutton";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];

Then, in the glassbutton app, you'll need to handle any special behavior within the app delegate method:

 - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {

    //your app specific code here for handling the launch

    return YES;
 }

Note that within the app you are opening the above delegate method will only get called AFTER the following method is called:

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

Handle accordingly, good luck.

crgt
  • 1,482
  • 1
  • 14
  • 17
  • 1
    NSString *urlString= @"glassbutton://com.yourcompany.glassbutton"; – makaron Aug 15 '13 at 10:23
  • What is glassbutton, by the way? – Erik Escobedo Jan 18 '15 at 02:18
  • It was the URL scheme mentioned in the original question. Best guess is that it was a specific reference to the app in question or the company producing it - you can define your URL scheme as desired within the relevant section of your app's info plist. – crgt Jan 18 '15 at 03:31