2016-09-29 21 views
3

我想從我的iOS應用程序中打開WIFI設置部分,我的代碼是與iOS 9.2如何斯威夫特打開WIFI設置3

if let settingsURL = URL(string: AppSettingsWifiUrl) { 
    UIApplication.shared.openURL(settingsURL) 
} 

斯威夫特3之前運作良好,但在更新之後不能在Xcode工作8 + Swift 3 + iOS 10,有人可以幫忙嗎?

+0

http://stackoverflow.com/questions/281525 26 /如何打開手機設置 - 當按鈕被點擊時 - ios –

+0

@SinaKH:感謝您的回覆,但它會打開應用程序設置我想打開WIFI設置。 – RJ168

回答

0

只需使用:

UIApplication.shared.openURL(URL(string:"prefs:root=WIFI")!) 
+1

它不適用於iOS10 – RJ168

0

使用iOS的10以下和以上:

if let url = URL(string:"App-Prefs:root=Settings&path=General") { 
    UIApplication.shared.openURL(url) 
} 
+0

你從哪裏得到這些信息? – winklerrr

0

這件事將與iOS 10也行,但你必須在UR項目設置信息添加URL類型。 URL方案應該是pref 如果您需要我將分享屏幕截圖,以便您可以輕鬆實現。

感謝

3
let url=URL(string: "App-Prefs:root=Privacy&path=Location") 
     if UIApplication.shared.canOpenURL(url!) 
     { 
      UIApplication.shared.open(url!, options: [:], completionHandler: {sucess in 

      }) 

     } 
     else{ 
      UIApplication.shared.open(url!, options: [:], completionHandler: {sucess in 

      }) 
     } 
4

可能iOS的10斯威夫特3

let url = URL(string: "App-Prefs:root=WIFI") //for WIFI setting app 
let app = UIApplication.shared 
app.openURL(url!) 
+0

你從哪裏得到這些信息?你能否提供一個資料來源? – winklerrr

+0

@winklerrr我在ios開發的wiki上找到了這個信息http://iphonedevwiki.net/index.php/Preferences.app和更多信息https://medium.com/@thanhvtrn/how-to-open-settings-無線網絡連接功能於迅速-ON-IOS-10-1d94cf2c2e60 – Lito

0

我們不能再這樣下去了iOS上的11,我們可以打開的設置:

if let url = URL(string:UIApplicationOpenSettingsURLString) { 
    if UIApplication.shared.canOpenURL(url) { 
     let url = UIApplication.shared.open(url, options: [:], completionHandler: nil) 
    } 
}