Opening URL in browser using C++ with cocos2d-x in iOS - iphone

I'm banging my brain against the wonderful lib xport that is cocos2d-x from the original cocos2d iOS library.
What I want to ask is how to open a web link in the safari browser? I don' know how to link the original objc code
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:]];
I have tried using the LUA engine, that is capable of executing shell commands, but I cannot find the safari app path to launch it.
Thanks, people.

You can't get the paths to other applications. However, if you make that openURL: call to open a URL with the http:// domain then Safari will open it. Have you tried that? What result do you get?
UPDATE:
Caveat: I'm not sitting in front of a machine where I can test this.
NSURL * url = [NSURL URLWithString:#"http://stackoverflow.com"];
[[UIApplication sharedApplication] openURL: url];
That should be all that is required. UIKit will switch to Safari and browse to the supplied URL.

Related

Maps.app is not opening programmatically

NSString *url = [NSString stringWithFormat: #"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f", currentLocation.latitude, currentLocation.longitude, coordinate.latitude, coordinate.longitude];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
I am trying open Maps application on iPhone from my application to show direction between two location. But, it is showing written directions in safari from google rather than opening maps application. Can anybody help me out.
You can launch other apps from your app. However, maps should respond to the http://maps.google.com schema. Typically, http://maps.google.com/ should launch the Maps application but I'm not sure why it is not.
Maps also supports maps:// and mapitem:// URL Schemes.
Update
The iOS Simulator does not have the Maps app, so obviously this isn't going to work in the simulator. Works as expected on a physical device though.

Force UIApplication openURL to use an existing tab, not open a new one

I'm using the following code to open a url in Safari on the iPad.
[[UIApplication sharedApplication] openURL:url];
The problem is that I need to open this URL in an existing tab, not open a new one. Is there any way to do this?
(why?: automated testing framework. I don't want the iPad to be bogged down by having hundreds of tabs open after running for a long period of time)
It is not possible to force Safari to load a URL in an existing tab. But I found out that if the exact same URL is already open in an existing tab, that tab is used when calling [[UIApplication sharedApplication] openURL:url];. So if you can ensure that you use the same URL in all of your tests, you should be able to avoid "hundreds of tabs".

Launching web app from native app

Does anyone know how to launch a web app from a native app?
I assume that this is hard to achive, but the next best thing would be to launch safari with a specific URL, without the URL-bar. And I don't want it to be done within the app, I would prefer if the native app could go into a suspended state.
It's not hard to achieve, it's easy with UIWebView http://developer.apple.com/library/ios/#documentation/uikit/reference/UIWebView_Class/Reference/Reference.html
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.makebetterthings.com/blogs/"]];
and enable multitasking in your app so when the safari opens your app will go in suspended mode.
Update -
Read my these blog entries -
http://www.makebetterthings.com/blogs/iphone/open-phone-sms-email-map-and-browser-apps-in-iphone-sdk/
http://www.makebetterthings.com/blogs/iphone/launching-your-own-application-via-a-custom-url-scheme/
unfortunately you can not open all the apps! but you can add custom URL scheme in your own app to open them

How to Open KeyNote app from another app

I have a situation where i have to use some keynote files in my app and for this i have to use Keynote app.
Now my question is that is there any method to open the keynote app from my app (might be from URL scheme). If yes then how to pass my file to that.
Is there any alternative to this i have never used Keynote that is why i have very less knowledge about it.
Please help.
There is no official mention of a URL scheme reference for the Keynote iOS app. If you want to try using Keynote files, I suggest you look at UIDocumentInteractionController. If there is an app that can open those files, it will provide the user options to open it.
You cannot open a file directly in Keynote from your app by passing it. But you can open Keynote from your app.
In Swift 3
let keynoteUrl = URL(string: "x-keynote-live://")
if UIApplication.shared.canOpenURL(keynoteUrl! as URL)
{
UIApplication.shared.open(keynoteUrl!)
}
In Objective-C
NSURL *keynoteUrl = [NSURL URLWithString:#"x-keynote-live://"];
if ([[UIApplication sharedApplication] canOpenURL:keynoteUrl]) {
[[UIApplication sharedApplication] openURL:keynoteUrl];
}

Open Photos app programmatically

Is it possible to launch the "Photos" application from an iPhone app? Similar to launching mail?
[[UIApplication sharedApplication] openURL:url];
The Photos app doesn't appear to register any URL schemes that other apps can use. There's a pretty well-established pattern in other system apps (e.g. Safari) of “saving an image” resulting in that image being placed in the user's camera roll; I'd recommend just sticking with that expected behavior, and perhaps using an alert to direct the user to look there for your app's exported image.
This article looks like it might be useful?
Getting images from the iPhone