在 Xcode 中打开 App 内的 URL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12310326/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 01:25:52  来源:igfitidea点击:

Open URL Within App in Xcode

iosxcodesafari

提问by Programmer...

In my application I want a URL to be open within the app not in safari, Thank You.

在我的应用程序中,我希望在应用程序中打开一个 URL,而不是在 safari 中,谢谢。

回答by Aaron Wojnowski

UIWebView is your answer if you want to load a webpage inside of your app.

如果您想在应用程序内加载网页,UIWebView 就是您的答案。

// example:

UIWebView *webView = [[UIWebView alloc] init];
[webView setFrame:CGRectMake(0, 0, 320, 460)];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://google.com"]]];
[[self view] addSubview:webView];

If you really want to get fancy, you can use your own UIApplication subclass and intercept the OpenURL method in your application and then pop up a modal view or something along those lines to open the URL in your app, when it normally would have opened the URL outside of your app.

如果你真的想要花哨,你可以使用你自己的 UIApplication 子类并拦截你的应用程序中的 OpenURL 方法,然后弹出一个模态视图或类似的东西来打开你的应用程序中的 URL,当它通常会打开应用程序之外的 URL。