我是iPhone新手。 我想在我的应用程序中打开一个网址。 我该怎么做这个任务?请建议我并提供一些有用的链接。iPhone:打开网址编程
23
A
回答
12
更新(2016):现在做这件事的最好方法是实例化并呈现SFSafariViewController。这为用户提供了Safari的安全性和速度,以及访问他们可能已经设置的任何cookie或Safari功能,而无需离开您的应用。
如果你想在Safari中打开的网址(和退出应用程序),您可以使用openURL method of UIApplication
如果你宁愿有它您的应用程序的内部处理,使用WKWebView。
5
如果你想打开,只是得到的URL数据,你可以使用NSString:
NSString *ans = [NSString stringWithContentsOfURL:url];
如果你正在试图获得来自URL的XML,你可以直接使用的NSXMLParser :
NSURL *url = [[NSURL alloc] initWithString:urlstr];
NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
// parse here
[parser release];
[url release];
在另一方面,如果通过打开你的意思是,在嵌入式浏览器打开一个URL,你可以使用UIWebView类。
76
显然上面给出的链接已经过时。这是UIApplication类的更新链接。
快速和简单的代码片段是:
// ObjC
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"http://www.google.com"]];
// Swift
UIApplication.shared.open(URL(string: "http://www.google.com")!, options: [:], completionHandler: nil)
3
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"https://medium.com/the-traveled-ios-developers-guide/swift-3-feature-highlight-c38f94359731#.83akhtihk"]]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://medium.com/the-traveled-ios-developers-guide/swift-3-feature-highlight-c38f94359731#.83akhtihk"]];
}
else{
[SVProgressHUD showErrorWithStatus:@"Please enable Safari from restrictions to open this link"];
}
相关问题
- 1. 远程打开网址
- 2. 网址未在iPhone上打开
- 3. iPhone - 按下按钮打开网址?
- 4. Fab打开网址
- 5. 打开网址开头铬://
- 6. 网址来打开Android应用程序
- 7. 打开网址使用Delphi
- 8. 从CSV打开网址
- 9. 打开网址发送POST
- 10. 打开网址处理
- 11. 用cmd打开网址
- 12. 在铬上打开网址
- 13. 使用javascript打开网址
- 14. 钛打开新的网址
- 15. h打开网址:selectOneMenu
- 16. iPhone打造编程
- 17. 如何从字符串中的WebView打开网址为iPhone
- 18. 如何打开iPhone上的按钮点击网址
- 19. Objective-C iPhone - 在Safari中打开多个网址
- 20. iPhone地址簿编程:ABPersonSetImageData
- 21. Iphone网络编程
- 22. 选择Iphone应用程序必须打开一个网址架构
- 23. 以编程方式打开iPhone的iPhone邮件客户端
- 24. 打开网址而无需在Chrome扩展程序中打开标签页?
- 25. 深层链接打开应用程序,但不打开确切的网址
- 26. 网址android系统编程
- 27. Django:打印网址的视图没有硬编码的网址
- 28. SAXParser如何无法打开网址?
- 29. 错误:网址无法打开流
- 30. tableviewcell打开网址点击迅速