iOS开发基础知识
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

然后如下代码:
[[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:0];
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:20];
dictAttr[NSForegroundColorAttributeName] = [UIColor whiteColor];
[navigationBar setTitleTextAttributes:dictAttr]; //更改导航条主题颜色
navigationBar.tintColor = [UIColor whiteColor]; //调整返回按钮当中标题的位置.(我们只要返回按钮的那个图片,但是不要上面的文字,移走文字就好了)
UIBarButtonItem *item = [UIBarButtonItem appearance];
[item setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -64) forBarMetrics:UIBarMetricsDefault];
} // 对于只修改nav的根控制器的某些样式,我们需要获取到nav的根控制器,但是上面的方法是类方法,拿不到rootVC,所以说要在pushViewController 中获取我们需要的控制器。
// 由于根控制器本质上也是由nav push而来的,所以说该方法能获得所有push的控制器
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
if (self.childViewControllers.count == 0) { // 判断是根控制器么,只有根控制器才需要设置menuIcon,其余push的控制器不需要
UIImage *leftBarBtnImage = [UIImage imageWithOriginalImageName:@"menuIcon"];
viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:leftBarBtnImage style:0 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 下面添加自己的数据就可以了。
iOS开发基础知识的更多相关文章
- IOS开发基础知识碎片-导航
1:IOS开发基础知识--碎片1 a:NSString与NSInteger的互换 b:Objective-c中集合里面不能存放基础类型,比如int string float等,只能把它们转化成对象才可 ...
- iOS开发——总结篇&IOS开发基础知识
IOS开发基础知识 1:Objective-C语法之动态类型(isKindOfClass, isMemberOfClass,id) 对象在运行时获取其类型的能力称为内省.内省可以有多种方法实现. 判断 ...
- IOS开发基础知识--碎片33
1:AFNetworking状态栏网络请求效果 直接在AppDelegate里面didFinishLaunchingWithOptions进行设置 [[AFNetworkActivityIndicat ...
- IOS开发基础知识--碎片42
1:报thread 1:exc_bad_access(code=1,address=0x70********) 闪退 这种错误通常是内存管理的问题,一般是访问了已经释放的对象导致的,可以开启僵尸对象( ...
- IOS开发基础知识--碎片50
1:Masonry 2个或2个以上的控件等间隔排序 /** * 多个控件固定间隔的等间隔排列,变化的是控件的长度或者宽度值 * * @param axisType 轴线方向 * @param fi ...
- IOS开发基础知识--碎片3
十二:判断设备 //设备名称 return [UIDevice currentDevice].name; //设备型号,只可得到是何设备,无法得到是第几代设备 return [UIDevice cur ...
- IOS开发基础知识--碎片11
1:AFNetwork判断网络状态 #import “AFNetworkActivityIndicatorManager.h" - (BOOL)application:(UIApplicat ...
- IOS开发基础知识--碎片14
1:ZIP文件压缩跟解压,使用ZipArchive 创建/添加一个zip包 ZipArchive* zipFile = [[ZipArchive alloc] init]; //次数得zipfilen ...
- IOS开发基础知识--碎片16
1:Objective-C语法之动态类型(isKindOfClass, isMemberOfClass,id) 对象在运行时获取其类型的能力称为内省.内省可以有多种方法实现. 判断对象类型 -(BOO ...
- IOS开发基础知识--碎片19
1:键盘事件顺序 UIKeyboardWillShowNotification // 键盘显示之前 UIKeyboardDidShowNotification // 键盘显示完成后 UIKeyboar ...
随机推荐
- ASP.NET Core MVC 2.x 全面教程_ASP.NET Core MVC 09. Model验证
数据注解 这样前后就会有div把这个inoput给包起来 添加一个Label使用TagHelper也有只能提示 出现的效果是这样的,实际上是把model的属性名打印出来.了. 把其他几个label也添 ...
- 任务48:Identity MVC:Model后端验证
任务48:Identity MVC:Model后端验证 RegisterViewModel using System; using System.Collections.Generic; using ...
- (水题)洛谷 - P1618 - 三连击(升级版)
https://www.luogu.org/problemnew/show/P1618 枚举所有的A,最多 $A_9^3$ ,然后生成B和C(先判断是不是能够生成),判断有没有重复数字(比之前那个优雅 ...
- 不常见偏门的Bug,Spring Boot IDEA 静态资源 图片访问404,初学者之殇
用过Idea朋友都知道,它有一个非常让人喜欢的功能就是:打算在某个a目录下创建一个hello.class文件,那么你仅需要右键点击New-Java Class- 然后输入名字:a.hello 即可. ...
- TensorFlow多线程输入数据处理框架(三)——组合训练数据
参考书 <TensorFlow:实战Google深度学习框架>(第2版) 通过TensorFlow提供的tf.train.batch和tf.train.shuffle_batch函数来将单 ...
- 如何使用go打出hell word
今天给大家带来一篇如何使用go打出hell word(手动滑稽) 关于go介绍的话,我就不多说了,在百度上一搜一大堆, 要使用的软件Visual Studio Code(VScode) 下载go的地址 ...
- php 中的引用(&)与foreach结合后的一个注意点
关于php中引用的概念及foreach循环的的应用就不多说了,php文档已经说的很明白了.直接上一段代码: <?php $arr = array(1,2, 3); foreach($arr as ...
- macOS 设置Root密码
用管理员帐号进入Terminal: 1) 输入:sudo passwd root ,回车: 2) 输入新的root密码: 3) 输入:su : 4) 输入新密码: 这样就进入到root帐号了.
- WIN7 X64的运行命令窗口
要在WIN7系统下用界面的方式执行运行命令,则可以用如下两种方法方法打开运行对话框.1.点Win+R(run)就能出来的.2.在开始菜单上点右键,选“属性”,进入开始菜单属性设置界面,单击底部的“自定 ...
- git部分指令
git stash #会把所有未提交的修改(包括暂存的和非暂存的)都保存起来,用于后续恢复当前工作目录 git stach pop #恢复之前缓存的工作目录 切换分支: git checkout de ...