1、在项目中的info.plist中添加URL Types并设置一项URL Schemes为prefs.如下图:
#import "ViewController.h"
#import "SecondViewController.h"
#import
@interface ViewController ()
@property(nonatomic,retain) NSArray *kJumpArr;
@property(nonatomic,retain) NSArray *kUrlArr;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self uiConfig];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
-(void)uiConfig{
self.view.backgroundColor=[UIColor whiteColor];
self.edgesForExtendedLayout=UIRectEdgeNone;
UIBarButtonItem *rightItem=[[UIBarButtonItem alloc] initWithTitle:@"next" style:UIBarButtonItemStylePlain target:self action:@selector(rightItemAction)];
self.navigationItem.rightBarButtonItem=rightItem;
CGFloat topSpace=((self.view.frame.size.height-64)-[self.kJumpArr count]*10-([self.kJumpArr count]-1)*15)/2;
for (int i=0;i<[self.kJumpArr count]; i++) {
UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
[btn setTitle:self.kJumpArr[i] forState:UIControlStateNormal];
[btn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[btn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
btn.tag=10+i;
[btn addTarget:self action:@selector(butttonAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
[btn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view.mas_top).offset(topSpace+i*25);
make.height.mas_equalTo(10);
make.centerX.equalTo(self.view.mas_centerX);
make.width.mas_equalTo(300);
}];
}
}
-(void)butttonAction:(UIButton *)button{
NSInteger num=button.tag-10;
NSURL *url=[NSURL URLWithString:self.kUrlArr[num]];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}
}
-(void)rightItemAction{
SecondViewController *VC=[[SecondViewController alloc] init];
[self.navigationController pushViewController:VC animated:YES];
}
-(NSArray *)kJumpArr{
if (_kJumpArr==nil) {
_kJumpArr=@[@"Brightness",@"Bluetooth",@"Date&Time",@"FaceTime",@"iClod",@"International"
,@"Location Services",@"Music",@"Network",@"Notes",@"Phone",@"Photos"
,@"VPN",@"Wallpaper",@"Wi-Fi",@"About",@"Accessibility",@"Airplane Mode On"];
}
return _kJumpArr;
}
-(NSArray *)kUrlArr{
if (_kUrlArr==nil) {
_kUrlArr=@[@"prefs:root=Brightness"
,@"prefs:root=General&path=Bluetooth"
,@"prefs:root=General&path=DATE_AND_TIME",@"prefs:root=FACETIME"
,@"prefs:root=CASTLE",@"prefs:root=General&path=INTERNATIONAL"
,@"prefs:root=LOCATION_SERVICES",@"prefs:root=Music"
,@"prefs:root=General&path=Network",@"prefs:root=NOTES"
,@"prefs:root=Phone",@"prefs:root=Photos",@"prefs:root=General&path=Network/VPN"
,@"prefs:root=Wallpaper",@"prefs:root=WIFI",@"prefs:root=General&path=About"
,@"prefs:root=General&path=ACCESSIBILITY"
,@"prefs:root=AIRPLANE_MODE"];
}
return _kUrlArr;
}
@end
#import "SecondViewController.h"
#import
@interface SecondViewController ()
@property(nonatomic,retain) NSArray *kJumpArr;
@property(nonatomic,retain) NSArray *kUrlArr;
@end
@implementation SecondViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self uiConfig];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
-(void)uiConfig{
self.view.backgroundColor=[UIColor whiteColor];
self.edgesForExtendedLayout=UIRectEdgeNone;
CGFloat topSpace=(self.view.frame.size.height-[self.kJumpArr count]*10-([self.kJumpArr count]-1)*15)/2;
for (int i=0;i<[self.kJumpArr count]; i++) {
UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
[btn setTitle:self.kJumpArr[i] forState:UIControlStateNormal];
[btn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[btn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
btn.tag=10+i;
[btn addTarget:self action:@selector(butttonAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
[btn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view.mas_top).offset(topSpace+i*25);
make.height.mas_equalTo(10);
make.centerX.equalTo(self.view.mas_centerX);
make.width.mas_equalTo(300);
}];
}
}
-(void)butttonAction:(UIButton *)button{
NSInteger num=button.tag-10;
NSURL *url=[NSURL URLWithString:self.kUrlArr[num]];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}
}
-(NSArray *)kJumpArr{
if (_kJumpArr==nil) {
_kJumpArr=@[
@"AutoLock",@"General",@"Keyboard",@"iCloud Storage & Backup",@"Music Equalizer",@"Music Volume Limit",@"Nike+iPod",@"Notification",@"Profile"
,@"Reset",@"Safari",@"Siri",@"Sounds",@"Software Update",@"Store"
,@"Twitter",@"Usage"];
}
return _kJumpArr;
}
-(NSArray *)kUrlArr{
if (_kUrlArr==nil) {
_kUrlArr=@[@"prefs:root=General&path=AUTOLOCK"
,@"prefs:root=General",@"prefs:root=General&path=Keyboard"
,@"prefs:root=CASTLE&path=STORAGE_AND_BACKUP",@"prefs:root=Music*path=EQ"
,@"prefs:root=Music&path=VolumeLimit",@"prefs:root=NIKE_PLUS_IPOD"
,@"prefs:root=NOTIFICATIONS_ID"
,@"prefs:root=General&path=ManagedConfigurationList",@"prefs:root=General&path=Reset"
,@"prefs:root=Safari",@"prefs:root=General&path=Assisitant"
,@"prefs:root=Sounds",@"prefs:root=General&path=SOFTWARE_UPDATE_LINK"
,@"prefs:root=STORE",@"prefs:root=TWITTER"
,@"prefs:root=General&path=USAGE"];
}
return _kUrlArr;
}
@end