2017-03-16 57 views
-1

我想打開我的iOS應用程序和URL,但是當我將NSURL放入基金應用程序print()不起作用。Appdelegate print()不起作用

請參閱這裏

import UIKit 

@UIApplicationMain 
class AppDelegate: UIResponder, UIApplicationDelegate { 
    var window: UIWindow? 
    var openUrl:NSURL? //This is used when to save state when App is not running before the url trigered 


    func application(_ application: UIApplication, openURL url: NSURL, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 
    //print("Host: \(url.host!)") 
    //let url = url.standardized 
    //NotificationCenter.default.post(name: NSNotification.Name(rawValue: "HANDLEOPENURL"), object:url!) 
    print("bbb") 
    return true 
    } 
} 
+0

,爲什麼你會使用'Foundation'而不是迅速? –

+0

你是什麼意思_「application print()不起作用。」_?你期望看到什麼?你真的看到了什麼? –

+0

@AshleyMills評論的附加內容:您是否收到任何警告/問題?我無法重現此錯誤 –

回答

1

沒有AppDelegate的方法與簽名,所以它沒有得到所謂的

func application(_ application: UIApplication, openURL url: NSURL, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool 

正確的方法簽名是:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool` 

你是用這種方法混淆它

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool 

編輯 爲了應對從網頁到iOS鏈接,請使用

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool { 
+0

它甚至不打印這個== func應用程序(_ application:UIApplication){ print(「bbb」) } – tumaz

+0

@tumaz我認爲你需要回顧iOS應用程序開發和Swift的基礎知識。你不能期望AppDelegate中的任意方法被調用。他們需要符合蘋果公司在其框架 – dmorrow

+0

我只是想喜歡上了Android – tumaz