Andy
Andy

Reputation: 14302

iOS Simulator WebApp/Bookmark for URL Scheme testing

I'm testing a custom URL scheme in my app, and I'd like to add a homescreen icon that calls that url. Whenever I request my custom URL, it opens my app, and then reverts Safari's address bar to the previously shown URL.

I tried to skirt this issue by editing the properties of another URL, e.g.

  1. Open Safari
  2. Navigate to http://google.com
  3. Tap the action button, and then "Add to home"

But this fails because you can't edit the URL assigned to the homescreen app.

As a fallback, I thought about just having a bookmark to the application, so I tried to bookmark a website and then edit the URL like this:

  1. Open Safari
  2. Navigate to http://google.com
  3. Tap the action button, and then "Bookmark"

but this fails because on the iOS simulator, you can't edit the URL of a bookmark (although you can do this on the device for some reason).

update: As tkanzakic points out, you can edit user-added bookmarks, just not the predefined bookmarks

Ideally, I'd like a homescreen app, but would settle for a bookmark instead.

Also, due to firewall restrictions, I can't connect this device to my Apple account, meaning I can't sync my Safari bookmarks either.

Upvotes: 6

Views: 4264

Answers (3)

Andy
Andy

Reputation: 14302

Ah, figured it out. You can get a webapp on the homescreen pointing to any URL by following these steps:

  1. In mobile safari, navigate to any webpage, tap the action button and make a home screen icon for this webpage.
  2. Close the simulator
  3. Open the directory /Users/<USERNAME>/Library/Application Support/iPhone Simulator/6.1/Library/WebClips
  4. The webclips folder stores all the homescreen webapps; find the one you just created and open the Info.plist file in a text editor.
  5. Edit the keys (such as URL and Title) as desired.

When you next relaunch the simulator, you homescreen webapp will point to the new URL.

Optionally, you can change the icon.png to change the webapp's icon.

Upvotes: 5

tkanzakic
tkanzakic

Reputation: 5499

As a fallback, I thought about just having a bookmark to the application, so I tried to bookmark a website and then edit the URL like this:

  1. Open Safari
  2. Navigate to http://google.com
  3. Tap the action button, and then "Bookmark"

but this fails because on the iOS simulator, you can't edit the URL of a bookmark (although you can do this on the device for some reason).

That is not true, it is possible to change the URL a bookmark, check this article to see how you can do it. I have done this on the Simulator and on a Device.

Upvotes: 2

Nikolai Ruhe
Nikolai Ruhe

Reputation: 81868

Just create a small app (using Xcode) that opens the URL in its application delegate:

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    [application openURL:[NSURL URLWithString:@"myappscheme://whatever/"]];
}

Note that I'm using applicationDidBecomeActive: instead of applicationDidFinishLaunching: to make the launcher app work after it has been launched before.

Alternatively you could set UIApplicationExitsOnSuspend in the Info.plist to force termination.

Upvotes: 0

Related Questions