2016-11-17 68 views
0

我正在與Swift 3 and Xcode 8 (iOS 10.1)合作,我對整個世界都是陌生的。 :)UIApplication.sharedApplication.open()不加載網址

我對外部應用程序進行身份驗證以獲取訪問令牌。用例是:

1)從我的應用程序

2)加載外部應用程序驗證用戶並獲得訪問令牌

3)從外部應用程序

我重定向到我的應用程序我能做1)和2),但不能3)。外部應用程序已指定您配置一個重定向參數,我已經完成了。但是,唉,沒有雪茄。

我已經爲兩個應用程序在Info.plist中設置了URL方案。我沒有在控制檯或調試器中發現任何錯誤。

我過去4天一直在使用Google進行搜索,這是我迄今爲止提出的解決方案。現在,我看到控制檯消息,但外部應用程序不再開放。

的AppDelegate

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool { 
    if (url.scheme == "extapp") { 
     print("working with extapp scheme") 
    } else if (url.scheme == "myapp") { 
     print("redirecting back to app after working with extapp") 
    } 
    return true 
    } 

的ViewController

@IBAction func loginButton(_ sender: Any) { 
    let id = text.text 
    let currentCharacterCount = id.text?.characters.count ?? 0 
    if currentCharacterCount == 0 { 
     self.showAlert(text: "Please provide a id.") 
    } else if currentCharacterCount < 10 { 
     self.showAlert(text: "Oh! id doesn't seem to be in the correct format. Try again.") 
    } else { 
     if (self.firebaseData.callAuth(loggedIn: id!)) { 
      OpenExtApp() 
     } 
    } 
} 

func OpenExtApp() { 
    let Url = URL(string: "extapp:///?autostart=\(token)&redirect=myapp://key") 
    if (UIApplication.shared.canOpenURL(Url!)) { 
     UIApplication.shared.open(Url!, options: [:]) 
    } 
} 

我會很感激你以任何方式幫助。

+0

是你在你的plist –

+0

添加URL模式'extapp' @ Anbu.Karthik是的,我有,如前所述在我的問題。 – Mina

+0

是否內部阻擋?,放置斷點並檢查一次。 –

回答

1

這個問題似乎已經與addingPercentEncoding方法我用編碼的redirect參數。我沒有注意到該參數沒有被正確編碼。事實證明,使用AllowedCharacters的默認過濾器不會編碼/和:。這是Apple的一個已知問題。這解決了編碼的問題,反過來,我被打開extapp遇到的問題:

let characterSetTobeAllowed = (CharacterSet(charactersIn: "!*'();:@&=+$,/?%#[] ").inverted) 
let redirect = parameter.addingPercentEncoding(withAllowedCharacters: characterSetTobeAllowed)