首页 技术 正文
技术 2022年11月6日
0 收藏 912 点赞 303 浏览 6212 个字

1:App跳转至系统Settings

跳转在IOS8以上跟以下是有区别的,如果是IOS8以上可以如下设置:

NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}

如果要兼容IOS7则要设置在URL Types中添加一个新项只填写prefs,然后设置一下上面那个URLWithString,对应的字符串如下:

About — prefs:root=General&path=About
Accessibility — prefs:root=General&path=ACCESSIBILITY
Airplane Mode On — prefs:root=AIRPLANE_MODE
Auto-Lock — prefs:root=General&path=AUTOLOCK
Brightness — prefs:root=Brightness
Bluetooth — prefs:root=General&path=Bluetooth
Date & Time — prefs:root=General&path=DATE_AND_TIME
FaceTime — prefs:root=FACETIME
General — prefs:root=General
Keyboard — prefs:root=General&path=Keyboard
iCloud — prefs:root=CASTLE
iCloud Storage & Backup — prefs:root=CASTLE&path=STORAGE_AND_BACKUP
International — prefs:root=General&path=INTERNATIONAL
Location Services — prefs:root=LOCATION_SERVICES
Music — prefs:root=MUSIC
Music Equalizer — prefs:root=MUSIC&path=EQ
Music Volume Limit — prefs:root=MUSIC&path=VolumeLimit
Network — prefs:root=General&path=Network
Nike + iPod — prefs:root=NIKE_PLUS_IPOD
Notes — prefs:root=NOTES
Notification — prefs:root=NOTIFICATIONS_ID
Phone — prefs:root=Phone
Photos — prefs:root=Photos
Profile — prefs:root=General&path=ManagedConfigurationList
Reset — prefs:root=General&path=Reset
Safari — prefs:root=Safari
Siri — prefs:root=General&path=Assistant
Sounds — prefs:root=Sounds
Software Update — prefs:root=General&path=SOFTWARE_UPDATE_LINK
Store — prefs:root=STORE
Twitter — prefs:root=TWITTER
Usage — prefs:root=General&path=USAGE
VPN — prefs:root=General&path=Network/VPN
Wallpaper — prefs:root=Wallpaper
Wi-Fi — prefs:root=WIFI
Setting —prefs:root=INTERNET_TETHERING

IOS开发基础知识–碎片44

IOS开发基础知识–碎片44

然后如下代码:

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

一段实例代码:

    NSURL *url;
if (isIOS8) {
url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
}
else
{
url=[NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"];
}
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}

2:iOS 获得手机当前语言,运用语言包跟地理名字运用

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSArray *allLanguage = [defaults objectForKey:@"AppleLanguages"];
NSString *currentLanguage = [allLanguage objectAtIndex:];
NSLog(@"The current language is : %@", currentLanguage);

iOS 9 之前:以上返回结果:语言字符串代码。例如:”zh-Hans”;iOS 9:以上返回结果:语言字符串代码 + 地区代码。例如:”zh-Hans-US”

简体中文:zh-Hans;繁体中文:zh-Hant;香港中文:zh-HK;澳门中文:zh-MO;台湾中文:zh-TW;新加坡中文:zh-SG

iphone 上的系统语言如果设为中文,则placemarks中打印出来的内容为中文城市名打印结果为 “北京市”,iphone 上的系统语言如果设为英文,则placemarks中打印出的内容为英文城市名打印结果为”beijing”,所以在获取地理名字时要做一个强制转换语言,让它可以兼容不管是什么语言都可以获取;下面一段时把中文强制转成英语,最后再转返手机默认的语言;

/**
* 通过实现代理方法,来获取到位置数据
*/
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations{
// course 方向(0°到359.9°,0°代表正北)
// speed 速度 m/s
// CLLocation 这个类封装了经纬度,海拔,移动方向,速度和位置等相关的信息 CLLocation *location = [locations lastObject]; // 地理反编码
// 1. 提供一个经纬度的坐标数据创建一个CLLocation对象(coorfinate : 坐标)
CLLocation *locationForRecode = [[CLLocation alloc] initWithLatitude:location.coordinate.latitude longitude:location.coordinate.longitude]; // 2. 创建地理反编码-反编码对象
CLGeocoder *geoCoder = [[CLGeocoder alloc] init];#warning keySteps :change System Language to English!!
// 如果当前系统语言为中文 则:先将 系统语言强制转换成英文,,获取到地理位置信息后再转为默认值 // 获取当前默认的系统语言 (先保存下来)
NSMutableArray *userDefaultLanguages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];
// 强制 转化为英文 (因为在请求天气预报的城市名时,需要英文状态下的城市名,)
// NSLog(@"%@",userDefaultLanguages);
// 系统默认语言 :zh-Hans-CN, en-CN
// 将语言强制转化为 英文
[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:@"en-CN", nil] forKey:@"AppleLanguages"]; // 3. 利用编码反编码对象,进行编码反编码操作
[geoCoder reverseGeocodeLocation:locationForRecode completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
if (error) {
// 反编码出错 打印错误信息
NSLog(@"地理编码出错:%@",error);
}else{
// 反编码成功,打印位置信息
// NSLog(@"%@",[placemarks lastObject].locality); NSString *cityName = [placemarks lastObject].locality; NSLog(@"placemarks==>>%@",placemarks); NSLog(@"%s,%@",__FUNCTION__,cityName);
// 调用 block
self.passCityNameToWeatherBlock(cityName); // 当 block 将英文城市名传出去后,立即 Device 语言 还原为默认的语言
[[NSUserDefaults standardUserDefaults] setObject:userDefaultLanguages forKey:@"AppleLanguages"];
}
}];
}

 3:设置navigationBar统一样式技巧总结

自定义一个WZYNavigationController继承于UINavigationController

#import "WZYNavigationController.h"  @interface WZYNavigationController ()  @end @implementation WZYNavigationController  // 当类被加载到内存的时候调用
+ (void)load
{ } // 当类第一次使用时调用
// 我们要在这个方法中设置指定当前自定义的控制器的导航条的样式
+ (void)initialize
{
/** 如果当前的navigationBar属于WZYNavigationController的,那么我们利用appearanceWhenContainedInInstancesOfClasses方法
来获取该类型的bar,然后统一设置属性。
注意后面参数是一个 “类的数组”
*/
UINavigationBar *navigationBar = [UINavigationBar appearanceWhenContainedInInstancesOfClasses:@[[WZYNavigationController class]]]; // bgImage
[navigationBar setBackgroundImage:[UIImage imageNamed:@"navBg"] forBarMetrics:UIBarMetricsDefault]; // 字体属性
NSMutableDictionary *dictAttr = [NSMutableDictionary dictionary];
dictAttr[NSFontAttributeName] = [UIFont systemFontOfSize:];
dictAttr[NSForegroundColorAttributeName] = [UIColor whiteColor];
[navigationBar setTitleTextAttributes:dictAttr]; //更改导航条主题颜色
navigationBar.tintColor = [UIColor whiteColor]; //调整返回按钮当中标题的位置.(我们只要返回按钮的那个图片,但是不要上面的文字,移走文字就好了)
UIBarButtonItem *item = [UIBarButtonItem appearance];
[item setBackButtonTitlePositionAdjustment:UIOffsetMake(, -) forBarMetrics:UIBarMetricsDefault];
} // 对于只修改nav的根控制器的某些样式,我们需要获取到nav的根控制器,但是上面的方法是类方法,拿不到rootVC,所以说要在pushViewController 中获取我们需要的控制器。
// 由于根控制器本质上也是由nav push而来的,所以说该方法能获得所有push的控制器
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
if (self.childViewControllers.count == ) { // 判断是根控制器么,只有根控制器才需要设置menuIcon,其余push的控制器不需要
UIImage *leftBarBtnImage = [UIImage imageWithOriginalImageName:@"menuIcon"];
viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:leftBarBtnImage style: target:self action:@selector(menuClick)];
} // 设置完样式之后再push(先push再设置还有什么鸟用?!)
[super pushViewController:viewController animated:animated];
} // leftBarBtn的监听方法,点击之后应跳转到leftView
// 为了拿到leftView,需要通知
- (void)menuClick
{
// 发送一个通知
[[NSNotificationCenter defaultCenter] postNotificationName:WZYLeftViewDidOpenDragNotification object:nil];
} @end

 4:[NSBundle mainBundle] pathForResource: ofType: 获取不到数据

从bundle中获取数据,明明把数据添加到项目中了,但就是不对。

NSString *newDataName = [[NSBundle mainBundle] pathForResource:dataName ofType:format];  为空

解决方法:

当时添加是直接拖拽过去,没有真正加入到bundle中,需要在项目设置中,build phases-》copy bundle resources 下面添加自己的数据就可以了。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,083
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,558
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,407
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,180
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,817
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,900