我是iOS开发的新手,当我通过自定义网址(foo://)打开应用时,我尝试将我的应用重定向到特定网站。使用此URL可以引导我进入AppDelegate。
func application(app: UIApplication, openURL url: NSURL, options:[String: AnyObject]) -> Bool {
let viewController = ViewController();
viewController.loadRequestExt()
return true
}
调用ViewController中的loadRequestExt()
函数
func loadRequestExt() {
super.viewDidLoad()
self.loadView()
let url = NSURL (string: "http://www.google.com");
let requestObj = NSURLRequest(URL: url!);
self.webView!.loadRequest(requestObj);
self.loadView()
}
override func loadView() {
print("loadView")
super.loadView()
let contentController = WKUserContentController();
contentController.addScriptMessageHandler(
self,
name: "iOS"
)
let config = WKWebViewConfiguration()
config.userContentController = contentController
self.webView = WKWebView(
frame: self.view.frame,
configuration: config
)
self.view = self.webView
self.webView?.navigationDelegate = self
// configure the activity view
activityView.center = self.view.center
activityView.hidesWhenStopped = true
activityView.startAnimating()
self.view.addSubview(activityView)
}
override func viewDidLoad() {
print("viewDidLoad")
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(registerPushToken), name: "didRegisterForRemoteNotificationsWithDeviceToken", object: nil)
let url = NSURL (string: "http://charlycares-frontend.herokuapp.com/#/app/login");
let requestObj = NSURLRequest(URL: url!);
self.webView!.loadRequest(requestObj);
}
它进入loadView并执行loadRequest
,但它保持在同一页面上。
答案 0 :(得分:0)
您必须在var text = Console.ReadLine();
while(!String.IsNullOrEmpty(text))
{
TextInfo ti = CultureInfo.CurrentCulture.TextInfo;
Console.WriteLine(ti.ToTitleCase(text).Replace(" ", string.Empty));
text = Console.ReadLine();
}
中将viewcontroller
设置为rootviewcontroller
窗口属性(我认为您没有使用故事板,在这种情况下,您必须设置appdelegate
作为初始viewcontroller
并且不向viewcontroller
添加代码):
appdelegate
在func application(app: UIApplication, openURL url: NSURL, options:[String: AnyObject]) -> Bool {
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = ViewController()
self.window?.makeKeyAndVisible()
return true
}
ViewController
中,拨打viewDidLoad
功能:
loadRequest