iOS开发之APP推送设置WIFI

本文介绍了一种在iOS应用中使用一行代码实现跳转至系统设置页面的方法,以便用户快速配置网络设置。同时提供了如何在项目的info.plist文件中设置URL types的具体步骤。

在iOS开发过程中,有时需要连接网络。当访问请求,检测到网络不可用时,需要提示用户手动进行设置网络并告知用户操作路径设置可用的网络。

只需一行代码即可实现:

- (void)viewDidLoad {

    [super viewDidLoad];

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

    button.backgroundColor = [UIColor redColor];

    button.frame = CGRectMake(50, 100, 100, 30);

    [self.view addSubview:button];

    [button addTarget:self action:@selector(pushSetting) forControlEvents:UIControlEventTouchUpInside]; 

}

- (void)pushSetting{

 NSURL *url = [NSURL URLWithString:@"prefs:root=WIFI"];

  BOOL isCanOpenURL = [[UIApplication  sharedApplication] openURL:url];//一行代码实现跳转

}

另补充:在项目中的info.plist中添加 URL types(NSArray) 并在item0(NSDictionary)中选出键为URL Schemes(NSArray),然后设置item0对应的值为prefs。或者直接在info项中的URL Types点击+直接设置URL Schemes

 

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

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=General&path=Restrictions"]];
http://stackoverflow.com/questions/8246070/ios-launching-settings-restrictions-url-scheme

List of currently known URLs in the Settings app:

  • prefs:root=General&path=About
  • prefs:root=General&path=ACCESSIBILITY
  • prefs:root=AIRPLANE_MODE
  • prefs:root=General&path=AUTOLOCK
  • prefs:root=General&path=USAGE/CELLULAR_USAGE
  • prefs:root=Brightness
  • prefs:root=General&path=Bluetooth
  • prefs:root=General&path=DATE_AND_TIME
  • prefs:root=FACETIME
  • prefs:root=General
  • prefs:root=General&path=Keyboard
  • prefs:root=CASTLE
  • prefs:root=CASTLE&path=STORAGE_AND_BACKUP
  • prefs:root=General&path=INTERNATIONAL
  • prefs:root=LOCATION_SERVICES
  • prefs:root=ACCOUNT_SETTINGS
  • prefs:root=MUSIC
  • prefs:root=MUSIC&path=EQ
  • prefs:root=MUSIC&path=VolumeLimit
  • prefs:root=General&path=Network
  • prefs:root=NIKE_PLUS_IPOD
  • prefs:root=NOTES
  • prefs:root=NOTIFICATIONS_ID
  • prefs:root=Phone
  • prefs:root=Photos
  • prefs:root=General&path=ManagedConfigurationList
  • prefs:root=General&path=Reset
  • prefs:root=Sounds&path=Ringtone
  • prefs:root=Safari
  • prefs:root=General&path=Assistant
  • prefs:root=Sounds
  • prefs:root=General&path=SOFTWARE_UPDATE_LINK
  • prefs:root=STORE
  • prefs:root=TWITTER
  • prefs:root=General&path=USAGE
  • prefs:root=VIDEO
  • prefs:root=General&path=Network/VPN
  • prefs:root=Wallpaper
  • prefs:root=WIFI
  • prefs:root=INTERNET_TETHERING
 

 

转载于:https://www.cnblogs.com/chims-liu-touch/p/5328430.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值