iOS开发基础知识--碎片44

 iOS开发基础知识--碎片44

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);// 调用 blockself.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开发基础知识--碎片44相关推荐

  1. iOS开发基础知识--碎片27

     iOS开发基础知识--碎片27 1:iOS中的round/ceil/floorf extern float ceilf(float); extern double ceil(double); ext ...

  2. iOS开发基础知识--碎片37

    iOS开发基础知识--碎片37 iOS开发基础知识--碎片37 iOS开发基础知识--碎片37 1:iOS 使用NJKWebViewProgress做webview进度条 引入头文件: #import ...

  3. iOS开发基础知识--碎片41

    iOS开发基础知识--碎片41 1:UIWebView加载本地的HTML NSString *path = [[NSBundle mainBundle] bundlePath]; NSURL *bas ...

  4. iOS开发基础知识--碎片19

    iOS开发基础知识--碎片19  1:键盘事件顺序 UIKeyboardWillShowNotification // 键盘显示之前 UIKeyboardDidShowNotification // ...

  5. IOS开发基础知识--碎片33

    1:AFNetworking状态栏网络请求效果 直接在AppDelegate里面didFinishLaunchingWithOptions进行设置 [[AFNetworkActivityIndicat ...

  6. IOS开发基础知识--碎片14

    1:ZIP文件压缩跟解压,使用ZipArchive 创建/添加一个zip包ZipArchive* zipFile = [[ZipArchive alloc] init];//次数得zipfilenam ...

  7. IOS开发基础知识--碎片13

    1:运行程序报the file couldn't be opened because you don't have permission to view it 解决办法:项目->targets- ...

  8. IOS开发基础知识--碎片45

    1:iOS SEL的简单总结 SEL就是对方法的一种包装.包装的SEL类型数据它对应相应的方法地址,找到方法地址就可以调用方法 a.方法的存储位置 在内存中每个类的方法都存储在类对象中 每个方法都有一 ...

  9. IOS开发基础知识--碎片34

    1:第三方插件SKSTableView在IOS7.1.1出现闪退的问题 解决办法,修改其内部源代码: (NSInteger)subRow { id indexpath = [NSIndexPath c ...

最新文章

  1. ASP.NET Web Pages – 帮助器简介
  2. 全球及中国软磁镍合金行业供需前景与投资策略研究报告2022版
  3. JSP指令标记和动作标记
  4. Remository3.52简体中文语言包
  5. 机器学习算法基础4-K-近邻算法、朴素贝叶斯算法、分类模型评估、模型的选择与调优
  6. mysql 查询关键词顺序
  7. SQL语句中exists/not exists的用法分析
  8. error: could not lock config file .git/config: Permission denied/Command failed with exit 255
  9. 织梦首页header实现会员的登录及会员状态显示
  10. python函数库 阶跃 信号函数 调用_使用numpy增加阶跃函数中的分辨率
  11. 将二维数组中最大值的 行和列的下标打印出来
  12. 5.Redis实战—秒杀业务
  13. Dos命令 netstat -ano 查看端口占用及关闭进程
  14. 移动CM201-2机顶盒系统设置apk
  15. Single-stage目标检测网络YOLO相关背景知识
  16. 从可回收火箭到AI向善 - 独家专访SpaceX前核心工程师Keenan Johnson
  17. ubuntu linux下制作win10启动盘
  18. 卧槽!福昕阅读器可以免费PDF转换啦?
  19. Awk使用及网站日志分析
  20. ad中电容用什么封装_电容补偿柜是做什么用的?

热门文章

  1. Android动画之Animator
  2. Swift 数字字符串格式化
  3. UILable在Autolayout模式下面自动调节字体大小
  4. ACM提交,C++,G++,C,GCC的区别
  5. Linux内核版本 uname命令 GNU项目 Linux发行版
  6. #include algorithm 常用函数
  7. JQuery轻量级网页编辑器 选中即可编辑
  8. java转换CSV文件生成xml格式数据
  9. 转载CSDN(educast):c# 对两个Datatable的结构相同进行合并
  10. 正则表达式中问号等特殊字符的转义(转)