开发者

Send user to Safari and perform a search with their configured search provider on iPhone?

I would like to be able to se开发者_开发问答nd the user out of my app and into Safari as if they had performed a search of some terms I provide. I realize I could construct a URL for doing a Google search and send them there, however the user has the option of configuring one of several search engines, and I'd like to use the one they've chosen and not Google.

Is there a way to do this?


I'm pretty sure this isn't possible.

On the iPhone you launch other applications by using a custom URL scheme. A good list of these can be found here: http://wiki.akosma.com/IPhone_URL_Schemes

So for example to launch Safari:

NSString *stringURL = @"http://my.url.com/";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];

The iPhone then decides to launch Safari as the URL scheme used is http. As you said in your question you can just use the correct URL to launch a search engine, so for Google:

http://www.google.com/search?q=MY_SEARCH_TERM

What would be ideal would be if Apple provided a URL scheme, such as search:// which launched the query in a search engine. However, this sadly isn't implemented.

I think the best way to "solve" your problem would be to allow the user to choose which search engine they'd like to use in your app. Then, when launching Safari you can use the appropriate URL. The added bonus is that you can also include search engines which Apple doesn't.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜