應用跳轉到系統設定的WiFi介面
阿新 • • 發佈:2019-01-29
1、在專案中的info.plist中新增URL Types並設定一項URL Schemes為prefs.如下圖:
2、該上程式碼了
[[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
NSLog(@"status=%@",[AFNetworkReachabilityManager sharedManager].localizedNetworkReachabilityStatusString );
if (status==AFNetworkReachabilityStatusNotReachable) {
UIAlertController *alert=[UIAlertController alertControllerWithTitle:@"提示" message:@"網路未連線" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction=[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}];
UIAlertAction *jumpAction=[UIAlertAction actionWithTitle:@"連線" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSURL *url=[NSURL URLWithString:@"prefs:root=WIFI"];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}
}];
[alert addAction:cancelAction];
[alert addAction:jumpAction];
[self presentViewController:alert animated:YES completion:nil];
}else{
UIAlertController *alert=[UIAlertController alertControllerWithTitle:@"" message:@"網路已連線" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction=[UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}];
[alert addAction:okAction];
[self presentViewController:alert animated:YES completion:nil];
}
}];
[[AFNetworkReachabilityManager sharedManager] startMonitoring];