2015-10-30 10 views
9

Ich versuche, die WiFi-Einstellungen durch meine Anwendung Objective-C mit zuzugreifen. Kann aber keinen Weg finden. Könnte mir jemand helfen?wie programmatisch zu öffnen, um die WiFi-Einstellungen in Objective-C in iOS9

bereits getestet mit:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=WIFI"]]; 

Funktioniert nicht auf iOS 9.

+0

Sie können nicht seit iOS5.1: http://stackoverflow.com/questions/8246070/ios-launching-settings-restrictions-url-scheme – Larme

+1

Dies ist ein Englisch-only-Website. Bitte übersetzen Sie (http://translate.google.com falls erforderlich). Oder verwende [Stackoverflow Portugiesisch] (http://pt.stackoverflow.com/). Este é um Inglês-only Website. Por favor, traduzir (Verwenden Sie http://translate.google.com se necessário). Verwenden Sie [Stackoverflow Português] (http://pt.stackoverflow.com/). – rmaddy

+0

Es tut mir leid, die Übersetzung wurde falsch gesendet. –

Antwort

11

Dies ist mein Code

if (&UIApplicationOpenSettingsURLString != NULL) { 
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=WIFI"]]; 
} 

Versuchen hinzufügen prefs URL-Schemata wie https://stackoverflow.com/a/31253743/3668465 tat

+5

Dies funktioniert nicht mit 'iOS 10'. Irgendwelche Arbeiten um? – unspokenblabber

+0

siehe [dies] (http://stackoverflow.com/questions/40126813/how-to-programmatical-open-the-wifi-settings-in-objective-c-on-i-ios-10) Post, um die Lösung –

2

Sie können nicht direkt auf Wi-Fi-Einstellung mit openURL bekommen. Alles, was Sie tun können, ist, Einstellungen für Ihre eigene App zu öffnen.

if (&UIApplicationOpenSettingsURLString != nil) { 
    NSURL *URL = [NSURL URLWithString:UIApplicationOpenSettingsURLString]; 
    [[UIApplication sharedApplication] openURL:URL]; 
} else { 
    ... 
} 
+0

geben Ihre Lösung öffnet das Menü der Anwendungseinstellungen. Ich frage mich, wie man das Menü für die WLAN-Einstellungen öffnet. –

+1

@HeltonSampaio Hast du den ersten Satz dieser Antwort gelesen? – rmaddy

+1

Ja Ja. Allerdings habe ich eine Anwendung auf meinem iPhone installiert, die genau das tut, was ich suche, sein Name ist der "Launcher", weißt du? Wenn diese Anwendung kann, weil wir das nicht tun können? –

-4

Sie können diese Option verwenden:

iOS> = 4.1 ist es möglich, SSID des drahtlosen Netzwerks zu erhalten, das Gerät currenctly verbunden ist.

Dazu würden Sie Funktion CNCopyCurrentNetworkInfo

Details zu Implemenation verwenden: iPhone get SSID without private library

+4

Wie erklärt dies, wie die Seite mit den WLAN-Einstellungen in der App "Einstellungen" unter iOS geöffnet wird? – rmaddy

7

Dies funktioniert auf iOS 10,

Zum Targets -> (Anwendung) -> Info -> URL-Typen -> +

Im URL Schemes Schreib

Prefs

Dann Rufen Sie an,

- (void)openWifiSettings 
{ 
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"prefs:root=WIFI"]]) { 
     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=WIFI"]]; 
    } else { 
     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"App-Prefs:root=WIFI"]]; 
    } 
} 
+4

zu erhalten Gebrochen in iOS 10. Irgendwelche Korrekturen? – shim

+1

Ja, das ist in iOS10 gebrochen – BigCheesy

+0

[This] (http://stackoverflow.com/questions/40126813/how-to-programmatically-open-the-wifi-settings-in-objective-c-oni-ios-10/42513576 # 42513576) funktioniert gut auf iOS 10 –

1
//Pre iOS 10 
NSURL *url = [NSURL URLWithString:@"prefs:root=WIFI"]; 
if (![[UIApplication sharedApplication] canOpenURL:url]) 
{ //iOS 10+ 
    url = [NSURL URLWithString:@"App-Prefs:root=WIFI"]; 
} 
[[UIApplication sharedApplication] openURL:url]; 
4

Alle Bedingungen:

NSURL * urlCheck1 = [NSURL URLWithString:@"App-Prefs:root=WIFI"]; 
    NSURL * urlCheck2 = [NSURL URLWithString:@"prefs:root=WIFI"]; 
    NSURL * urlCheck3 = [NSURL URLWithString:UIApplicationOpenSettingsURLString]; 

    if ([[UIApplication sharedApplication] canOpenURL:urlCheck1]) 
    { 
     [[UIApplication sharedApplication] openURL:urlCheck1]; 
    } 
    else if ([[UIApplication sharedApplication] canOpenURL:urlCheck2]) 
    { 
     [[UIApplication sharedApplication] openURL:urlCheck2]; 
    } 
    else if ([[UIApplication sharedApplication] canOpenURL:urlCheck3]) 
    { 
     [[UIApplication sharedApplication] openURL:urlCheck3]; 
    } 
    else 
    { 
     //Unable to open settings app. 
    } 
+0

Nützlich .. danke – nix

Verwandte Themen