iOS: Is it possible to open NSURLRequest directly in Safari?

房东的猫 提交于 2019-11-29 07:25:11
MrGomez

I'm going to put my neck on the line and say no — there's no way to pass an NSURLRequest directly to Safari. The (primary) inter-application communication medium on iOS is to access URLs; there's no general mechanism for passing objects from one application to another.

I think the best you're going to be able to do is to fetch a one-time key from your web server in the app, then pop into Safari with that in the URL. And, if you can, do that via HTTPS so that the URL path and query components are only visible once TLS negotiation has succeeded. That should stop anybody else from seeing the relevant credentials and stop them from being useful even if they're obtained by some other means (such as somebody next to you copying the URL from your screen).

Michael Dorst

It would be simpler to use an NSURL, or just an NSString, or just a char* for that matter. I'm not sure if that works on the iPhone, it should, since the iPhone runs parallel with Darwin just like OSX, but there are some restrictions to that on the iPhone. This definitely works on a mac though.

NSString *url = @"http://www.apple.com";
NSURL *myURL = [NSURL URLWithString:url];
system([ [NSString 
          stringWithFormat:@"Open -a Safari %@", 
          [NSString stringWithContentsOfURL:myURL encoding:NSUTF8StringEncoding error:NULL] ]
          cStringUsingEncoding:NSUTF8StringEncoding]);

Also, I might suggest that that's a bad idea (if it might be avoided). As an iPhone user, I'm sure I'm not alone in finding it very irritating when developers take me away from the app I'm currently in.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!