iOS工程适配64-bit经验分享
- 格式:doc
- 大小:28.50 KB
- 文档页数:10
iOS9--适配系列教程(原⽂译⽂)iOS9适配系列教程【中⽂在】(截⾄2015年9⽉3⽇共有6篇,后续还将持续更新。
更多iOS开发⼲货,欢迎关注)For more infomation ,welcome to followEnglish1. Demo1_You'd better Convert HTTP to HTTPSHow to deal with the SSL in iOS9,One solution is to do like:As the say :iOS 9 and OSX 10.11 require TLSv1.2 SSL for all hosts you plan to request data from unless you specify exception domains in your app's Info.plist file.The syntax for the Info.plist configuration looks like this:<key>NSAppTransportSecurity</key><dict><key>NSExceptionDomains</key><dict><key></key><dict><!--Include to allow subdomains--><key>NSIncludesSubdomains</key><true/><!--Include to allow insecure HTTP requests--><key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key><true/><!--Include to specify minimum TLS version--><key>NSTemporaryExceptionMinimumTLSVersion</key><string>TLSv1.1</string></dict></dict></dict>If your application (a third-party web browser, for instance) needs to connect to arbitrary hosts, you can configure it like this:<key>NSAppTransportSecurity</key><dict><!--Connect to anything (this is probably BAD)--><key>NSAllowsArbitraryLoads</key><true/></dict>If you're having to do this, it's probably best to update your servers to use TLSv1.2 and SSL, if they're not already doing so. This should be considered a temporary workaround. As of today, the prerelease documentation makes no mention of any of these configuration options in any specific way. Once it does, I'll update the answer to link to the relevant documentation.If your server is support TLSv1.2 ,but you also have to do what I say just now if you want to connect success in iOS9:After some discussion with Apple Support, the issue is due to the self signed certificate.ATS trusts only certificate signed by a well known CA, all others are rejected. As a consequence the only solution with a Self signed certificate is to set an exception with NSExceptionDomains.2.Demo2_iOS9 new feature in CoreLocation : background only when you needIf you're using CoreLocation framework in your app in Xcode7(pre-released),and you may notice that there is a newly added property called allowsBackgroundLocationUpdates in CLLocationManager class.This new property is explained in the WWDC session .The default value is NO if you link against iOS 9.If your app uses location in the background (without showing the blue status bar) you have to set allowsBackgroundLocationUpdates to YES in addition to setting the background mode capability in Info.plist. Otherwise location updates are only delivered in foreground. The advantage is that you can now have location managers with background location updates and other location managers with only foreground location updates in the same app. You can also reset the value to NO to change the behavior.The documentation is pretty clear about it:By default, this is NO for applications linked against iOS 9.0 or later, regardless of minimum deployment target.With UIBackgroundModes set to include "location" in Info.plist, you must also set this property to YES at runtime whenever calling -startUpdatingLocation with the intent to continue in the background.Setting this property to YES when UIBackgroundModes does not include "location" is a fatal error.Resetting this property to NO is equivalent to omitting "location" from the UIBackgroundModes value. Access to location is still permitted whenever the application is running (ie not suspended), and has sufficient authorization (ie it has WhenInUse authorization and is in use, or it has Always authorization). However, the app will still be subject to the usual task suspension rules.See -requestWhenInUseAuthorization and -requestAlwaysAuthorization for more details on possible authorization values.Set Info.plist like:The syntax for the Info.plist configuration looks like this:<key>NSLocationAlwaysUsageDescription</key><string>微博@iOS程序犭袁请求后台定位权限</string><key>UIBackgroundModes</key><array><string>location</string></array>Use like:_locationManager = [[CLLocationManager alloc] init];_locationManager.delegate = self;[_locationManager setDesiredAccuracy:kCLLocationAccuracyBest];if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8) {[_locationManager requestAlwaysAuthorization];}if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9) {_locationManager.allowsBackgroundLocationUpdates = YES;}[_locationManager startUpdatingLocation];3.iOS9 Untrusted Enterprise Developer with no option to trustSince iOS9 there is no option to trust an enterprise build. Before iOS9,it's very easy to use:if you touch the app,it'll apear this :Now:You have to let the user do like: Go to Settings - General - Profiles - tap on your Profile - tap on Trust button.4.bitcode optionalAfter Xcode 7,bitcode option will be enabled by default,If your library was compiled without bitcode but the bitcode option is enabled in your project settings.You can1. Update your library with bit code, or you'll get warnings like:(null): URGENT: all bitcode will be dropped because '/Users/myname/Library/MobileDocuments/com~apple~CloudDocs/foldername/appname/GoogleMobileAds.framework/GoogleMobileAds(GADSlot+AdEvents.o)' was built without bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. Note: This will be an error in the future.1. Say NO to Enable Bitcode in your target Build Settingsand the Library Build Settings to remove the warningsFor more information,go to,and WWDC 2015 Session 102:5.Privacy and Your App【URL scheme changes】iOS 9 has made a small change to the handling of URL scheme. You must whitelist the url's that your app will call out to using the LSApplicationQueriesSchemes key in your Info.plist. The main conclusion is that:If you call the “canOpenURL” method on a URL that is not in your whitelist, it will return “NO”, even if there is an app installed that has registered to handle thisscheme. A “This app is not allowed to query for scheme xxx” syslog entry will appear.If you call the “openURL” method on a URL that is not in your whitelist, it will fail silently. A “This app is not allowed to query for scheme xxx” syslog entry will appear. The author also speculates that this is a bug with the OS and Apple will fix this in a subsequent release.This is a new security feature of iOS 9. Watch for more information.Any app built with SDK 9 needs to provide a LSApplicationQueriesSchemes entry in its plist file, declaring which schemes it attempts to query.<key>LSApplicationQueriesSchemes</key><array><string>urlscheme</string><string>urlscheme2</string><string>urlscheme3</string><string>urlscheme4</string></array>Assuming two apps TestA and TestB. TestB wants to query if TestA is installed. "TestA" defines the following URL scheme in its info.plist file:<key>CFBundleURLTypes</key><array><dict><key>CFBundleURLSchemes</key><array><string>testA</string></array></dict></array>The second app "TestB" tries to find out if "TestA" is installed by calling:[[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:@"TestA://"]];But this will normally return NO in iOS9 because "TestA" needs to be added to the LSApplicationQueriesSchemes entry in TestB's info.plist file. This is done by adding the following code to TestB's info.plist file:<key>LSApplicationQueriesSchemes</key><array><string>TestA</string></array>6. Support Slide Over and Split View of iOS 9How to transition an an older project to support Slide Over and Split View of iOS 9? You may find that all the demo projects was written by storyboard or xib, but the older project's UI is written by code!I would suggest switching to storyboards to make your life easy.I would highly recommend you watch the following WWDC videos and then think about what exactly you need to do in order to support multi tasking.1.2.3.4.5.LicensePosted by中⽂1. Demo1_iOS9⽹络适配_ATS:改⽤更安全的HTTPS[摘要]为了强制增强数据访问安全, iOS9 默认会把所有的http请求所有从NSURLConnection、CFURL、NSURLSession发出的 HTTP 请求,都改为 HTTPS 请求:iOS9.x-SDK编译时,默认会让所有从NSURLConnection、CFURL、NSURLSession发出的 HTTP 请求统⼀采⽤TLS 1.2 协议。
苹果工程模式操作方法
苹果工程模式是苹果公司开发和发布软件以及硬件设备的一种操作和管理方法。
以下是一般苹果工程模式的操作方法:
1. 开发环境搭建:安装和配置开发环境,包括Xcode开发工具、苹果开发者账号、相关的SDK(软件开发工具包)等。
2. 项目创建:在Xcode中创建一个新的项目,选择合适的模板(例如iOS应用程序或macOS应用程序)。
3. 编码和测试:使用合适的编程语言(如Objective-C或Swift)编写代码,并进行测试和调试以确保代码的正确性和稳定性。
4. 用户界面设计和交互:设计和开发用户界面,包括布局、图形、动画以及用户交互逻辑等。
5. 调试和优化:使用Xcode提供的调试工具来识别和修复应用程序中的错误和性能问题,以达到更好的用户体验和应用程序稳定性。
6. 应用程序发布:通过苹果开发者账号,将应用程序提交到苹果官方的App Store进行审核和发布。
7. 版本管理:使用版本控制工具(如Git)对项目进行管理,以便开发团队能够协同工作、追踪代码修改和恢复历史版本。
8. 持续集成:建立持续集成流程,包括自动化构建、代码静态分析、单元测试等,以提高开发效率和代码质量。
9. 用户反馈和更新:定期收集用户反馈和意见,根据反馈进行应用程序的改进和更新。
总之,苹果工程模式涵盖了从开发到发布整个应用程序生命周期的一系列操作和管理方法,以确保高质量的iOS和macOS应用程序的开发和发布。
网易视频云技术分析:IOS工程常见问题解决方法网易视频云是网易推出的视频云服务,目前已经y广泛应用于在线教育、秀场直播、远程医疗、企业协作等领域。
现在,网易视频云的技术专家们给大家分享一则移动APP测试技术文:IOS工程常见问题解决方法。
最近在做IOS测试时,碰到了几个环境引起的问题,主要是开发工具新版本及IOS系统新版本特性导致。
现挑取两个比较典型的问题来分享给大家。
1. Xcode版本引出的问题问题描述:开发提测时,创建的工程是在xcode6版本上创建的,而测试环境使用新的版本Xcode7,将开发提测工程导入后进行编译报如下错误:ld:'/Users/netease/Downloads/nos-ios-demo-for-stabilitytest/NOSSDKDemo/libnos iosSDK.a(NOS.o)' does not contain bitcode. You must rebuild it with bitcodeenabled(Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcodeforthis target. for architecture arm64clang: error: linker command failed with exit code 1 (use -v to see invocation)具体如图显示:问题分析:通过编译过程所报的错误,很明显的可以看出是第三方库不包含bitcode 问题,具体来看下官方对于bitcode解释Bitcode is an intermediate representationof a compiled program. Apps you upload to iTunes Connect that contain bitcodewill be compiled and linked on the App Store. Including bitcode will allowApple to re-optimize your app binaryin the future without the need to submit anew versionof your app to the store.Bitcode. When you archive for submission tothe App Store, Xcode will compile your app into an intermediate representation.The App Store will then compile the bitcode down into the 64or32 bitexecutables as necessary.通过上面的解释我们可以看出,bitcode属于被编译程序的一种中间形态,类似于c中的.o文件。
delphi xe2开发ios环境的安装与设置硬件设施:支持硬件虚拟化的cpu,至少2G的内存,处理器intel的(近几年上市的机子基本支持虚拟化,amd的就算了基本安装不了)。
操作系统32,64位的都可以。
软件准备:Vmware Workstation 7.1以上的版本(我用的是8.0.1build-538992) Mac os X Lion镜像Xcode 4.2 ios sdk 5 b1Rad Studio XE2(本人用的是delphicbuilder_xe2_4358_win_dl)Firemonkey-ios.dmg(该镜像在XE2的安装目录下面有,下面会提到)以及为Mac系统在虚拟机中正常使用的Vmware tools和进入Mac系统的引导文件。
Mac X OS Lion在虚拟机中的安装大家在Windows系统中安装完Vmware后就可以在里面虚拟Mac系统了,其实安装Mac系统的基本操作步骤都是相似的,本人就以我成功安装的过程演示给大家。
本人之前在7.1.3破解中文版上安装成功过,但是还是有很多小问题,最后导致系统都重装了,所以说用的软件一定要来自官方正版的好,其他版本的质量不敢保证。
不过在安装之前先要查看本机是否支持虚拟化,如果不支持,一切都等于白说。
你可以到网上下载一个专门的测试虚拟化的软件,检测下本机是否支持虚拟化,也可以在网上查找有关于本机的配置是否支持虚拟化,总而言之机器一定要支持虚拟化。
下面我演示给大家看我具体的操作步骤。
1、打开VMware Workstation,新建虚拟机。
(如图)2、进入新建虚拟机向导(如图)选择自定义3、选择虚拟机硬件兼容性,直接下一步。
4、选择“我以后再安装操作系统”,然后下一步。
(如图)5、这一步需要说明下,有些同学呢可能会从其他地方下载补丁过来,为了方便操作。
本人没有下载补丁,按图中所选择,然后点击下一步(如图)6、命名虚拟机(如图),位置建议你换个盘,毕竟放在C盘很占系统盘空间,下一步。
金蝶 K/3 CloudV5.0 系统环境部署目录1系统部署环境 (1)1.1系统的部署角色 (1)1.2系统的访问模型 (2)1.3推荐的部署方式 (3)1.4支持的运行环境 (4)1.4.1应用服务器的运行环境 (4)1.4.2管理中心的运行环境 (6)1.4.3数据库的运行环境 (6)1.4.4客户端的运行环境 (8)1.5推荐的网络和硬件配置 (13)1.5.1网络配置 (13)1.5.2服务器配置 (13)1.5.3客户端配置 (14)1系统部署环境1.1系统的部署角色1.2系统的访问模型用户的访问模型:用户 -> 应用服务器 ->账套数据库管理员的访问模型:管理员 -> 管理中心 -> 应用服务器/ 账套数据库/ 管理数据库图示↑系统访问模型管理员的部署初始任务:安装系统 -> 访问管理站点 -> 新建管理中心 -> 新建账套 -> 注册应用服务器到管理中心(应用服务器和管理中心在同一机器则不需注册)用户许可管理在『管理中心』建立后随时可进行。
仅『应用服务器』和『管理中心』需要系统安装,数据库均不需要系统安装,通过管理中心站点访问SQL Server或Oracle DB即可新建和维护账套数据库、管理数据库。
具体安装部署过程请见安装盘中的《产品安装指南》。
1.3推荐的部署方式管理中心、管理数据库耗费资源都比较少,为了部署便捷性起见,通常推荐生产环境将应用服务器、管理中心装在同一操作系统上,账套、管理数据库放在另一台服务器的同一数据库实例中。
这样只需两台服务器即可完成系统部署,性能也有保障。
图示↑生产环境的一般部署方式如果部署系统是为了完成演示、功能测试、开发等轻量级的非生产任务,可以将所有服务器角色都部署在同一台服务器的同一操作系统中,但在客户生产环境禁止这样做。
如果系统需要做群集或有更高的安全考虑,可按需将各角色分开部署,这样要两台以上服务器才能完成部署。
移动端深度学习推理框架总结移动端深度学习推理框架框架公司⽀持硬件特性相关资源TensorFlow Lite Google2017CPUGPU: android基于OpenGL, IOS基于Metalapp内核优化,pre-fused激活,更快更⼩模型定量化https:///lite/performance/gpu_advanced?hl=zh-cnhttps:///lite/https:///amitshekhariitbhu/Android-TensorFlow-Lite-ExampleCore ML Apple 2017IOS(Accelerate(CPU)/Metal(GPU)) Core ML 在设备端可以利⽤⽤户数据进⾏重新训练或优化。
https:///documentation/coremlhttps:///likedan/Awesome-CoreML-Modelshttps:///cn/documentation/coreml/#overviewCaffe2Facebook2017IOS,Android CPU GPU暂⽆资料,针对具有NEON指令的ARM CPU进⾏优化,其性能超过iphone6的GPU优化的。
https:///facebookarchive/caffe2https://caffe2.ai/docs/zoo.htmlhttps:///caffe2/modelsNCNN Tencnet2017Android: CPU/GPU 32/ 64bit都⽀持IOS: CPU 32/64bit GPU 64 bit⽀持全平台,主要针对⼿机端进⾏极致的优化,⽆第三⽅依赖库,但算⼦⽀持相对较少。
https:///Tencent/ncnnhttps:///BUG1989/caffe-int8-convert-tools.gitPaddle-Mobile Baidu 2017Android: CPU GPU基于OpenCL仅⽀持Androidhttps:///PaddlePaddle/paddle-mobilehttps:///PaddlePaddle/PaddleQNNPACK/NNPACK(加速库)Facebook Android / IOS主要针对卷积计算进⾏加速处理,armeabi-v7a需要CPU⽀持NEON指令,暂⽆GPU信息https:///pytorch/QNNPACKhttps:///p/81026071https:///Maratyszcza/NNPACKMACE XIAOMI2018⽀持Android / IOS CPU,GPU底层算⼦基于OpenCL实现https:///XiaoMi/macehttps:///XiaoMi/mace-modelshttps://mace.readthedocs.io/en/latest/chinese.htmlMNN 阿⾥2019Android / IOS (CPU / GPU)通⽤性较好,算⼦⽀持性好https:///alibaba/MNNTNN Tencent2020Android / IOS (ARM CPU /GPU /NPU)主要针对于移动端,基于NCNN开发,性能移动端略优于MNN。
51CTO学院-iOS8开发视频教程Swift语言版-Part 3iOS 8多分辨率屏幕适配-iOS就业班iOS8开发视频教程Swift语言版-Part 3:iOS 8多分辨率屏幕适配-iOS就业班课程目标本视频教程属于iOS企业级开发就业系列课程的一部分,基于Swift开发语言,iOS8版本视频课程。
全套课程一共分为15部分,智捷课堂结合国内多家IT公司iOS开发企业内训需求和实战开发经验进行总结,精心定制本套课程以培养适合企业需求的iOS开发工程师,以培养高质量的iOS从业者为目标。
适用人群iOS开发初学者,iOS开发入门,对移动开发感兴趣的同学课程学习由于苹果不断更新新产品,多分辨率适配也应该引起大家注意,本课程主要介绍了iOS8后设备屏幕的多样性,iOS8后布局的改变,以及教大家如何进行多屏幕适配。
本视频教程属于iOS企业级开发就业系列课程的一部分,基于Swift开发语言,iOS8版本视频课程。
全套课程一共分为15部分,智捷课堂结合国内多家IT公司iOS开发企业内训需求和实战开发经验进行总结,精心定制本套课程以培养适合企业需求的iOS开发工程师,以培养高质量的iOS从业者为目标。
第一章 3.1 iOS 8屏幕的多样性3课时40分钟1iOS 8屏幕介绍2iOS 8的三种分辨率3获得iOS设备屏幕信息第二章 3.2 iOS屏幕布局2课时15分钟4iOS中的“栏”5传统布局第三章 3.3 Auto Layout布局3课时35分钟6Interface Builder中管理Auto Layout 约束7实例:Auto Layout布局8Auto Layout布局第四章 3.4 Size Class与iOS 8多屏幕适配4课时55分钟9Size Class与iOS 8多屏幕适配10Interface Builder中使用Size Class11Size Class的九宫格12实例:使用Size Class第五章 3.5 屏幕滚动视图中使用Auto Layo ut和Size2课时35分钟13屏幕滚动视图重要的属性14实例:屏幕滚动视图第六章 3.6 使用资源目录(Asset catalog)管理图片1课时10分钟15使用资源目录(Asset catalog)管理图片学员评价:学员笔记:。
安裝說明請詳見下列網址連結.I nstructions in English are available at the link below.L as instrucciones de instalación en el español se encuentran disponibles en el enlace que se indica a continuación.L es instructions d’installation en français sont disponibles au lien suivant.E ine Anleitung in englischer Sprache ist unter dem unten stehenden Link verfügbar.I nstructies in het Nederlands zijn beschikbaar via onderstaande link.日本語 のインストールガイドは下記リンク先でご覧いただけます。
한국어로 작성된 설치 지침은 아래 링크에서 볼 수 있습니다.Инструкции по установке на русском языке можно найти по ссылке ниже.L e istruzioni per l’installazione in italiano sono disponibili nel link indicato in basso.P ode encontrar as instruções de instalação em português através do link em baixo.I nstrukcja w języku polskim są dostępne w linku poniżej.ค�แนะนำ�ในก�รติดตังไทยมีจดไว้ให้ผ�นลิงค์ตอไปนี/DragonFlyCobalt/flight23简介 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .4包装清单/支持的操作系统. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..6概览:DragonFly Cobalt .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..7安装 .DragonFly .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .8制式的重要性 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .8如何在 .Apple .OS .X .上使用 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .10如何在 .Windows .上使用 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .12如何在 .Apple .移动设备上使用. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..14如何在 .Android .设备上使用 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..15桌面设备应用管家 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 17发挥 .DragonFly .的更大威力 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..20用于电脑的 .Direct .或 .DragonTail .C USB .3 .相机套件带来最大性能和可靠性用于 .Android .的 .DragonTail .Micro .或 .C 耳机和耳塞插电扬声器放大器或接收器4DragonFly CobaltUSB 数字模拟转换器DragonFly .是一款 .USB .数字模拟转换器 .(DAC),设计的初衷就是为了让电脑、智能手机甚至是平板电脑传递更清晰、更细腻、更自然甜美的音质。
终究还是来了。
Apple下发了支持64位的最后通牒:As we announced in October, beginning February 1, 2015 new iOS apps submitted to the App Store must include 64-bit support and be built with the iOS 8 SDK. Beginning June 1, 2015 app updates will also need to follow the same requirements.早应该做的适配终于要开始动工了,苦了64位的CPU运行了这么久32位的程序。
前段时间公司项目完成了64-bit包的适配,本没那么复杂的事被无数不标准的老代码搅和的不轻,总结几个Tip 共勉。
Tips拒绝基本数据类型和隐式转换首当其冲的就是基本类型,比如下面4个类型在32-bit和64-bit下分别是多长呢?size_ts1=sizeof(int);size_ts2=sizeof(long); size_ts3=sizeof(float);size_ts4=sizeof(double);32-bit下:4, 4, 4, 8;64-bit下:4, 8, 4, 8(PS:这个结果随编译器,换其他平台可不一定)它们的长度变化可能并非我们对64-bit 长度加倍的预期,所以说,程序中出现sizeof的代码多看两眼。
而且,除非你明确知道自己在做什么,应该使用下面的类型代替基本类型:int -> NSIntegerunsigned -> NSUIntegerfloat -> CGFloat动画时间-> NSTimeInterval…这些都是SDK中定义的类型,而我们大部分时间都在跟SDK的API们打交道,使用它们能将类型转换的影响降低很多。
再比如说下面的代码:NSArray*items=@[@1,@2,@3];for(inti=-1;i结果是,for循环一次都没有进。
数组的count是NSUInteger类型的,-1与其比较时隐式转换成NSUInteger,变成了一个很大的数字:(lldb)pi(int)$0=-1(lldb)p(NSUInteger)i(NS UInteger)$1=18446744073709551615这和64-bit到没啥关系,想要说明的是,这种隐式转换也需要小心,一定要注意和这个变量相关的所有操作(赋值、比较、转换)老式for循环可以考虑写成:for(NSUIntegerindex=0;index当然,数组遍历还是更推荐用for-in或block版本的,它们之间的比较可以回顾下这篇文章。
使用新版枚举和上面的原因差不多,枚举应该使用新版的写法:typedefNS_ENUM(NSInteger,UIViewAni mationCurve){UIViewAnimationCurveEase InOut,UIViewAnimationCurveEaseIn,UIVie wAnimationCurveEaseOut,UIViewAnimati onCurveLinear};不仅能为枚举值指定类型,而且当赋值赋错类型时,编译器还会给出警告,没理由不用这种写法。
替代Format字符串适配64-bit时,你是否遇到了下面的恶心写法:NSArray*items=@[@1,@2,@3];NSLog(@”数组元素个数:%lu”,(unsignedlong)items.count);一般情况下,利用NSNumber的@语法糖就可以解决:NSArray*items=@[@1,@2,@3];NSLog(@”数组元素个数:%@”,@(items.count));同理,int转string也可以:NSIntegeri=10086;NSString*string=@(i).s tringValue;当然,如需要%.2f这种Format 就不适用了。
64-bit下的BOOL32-bit下,BOOL被定义为signed char,@encode(BOOL)的结果是'c' 64-bit下,BOOL被定义为bool,@encode(BOOL)结果是'B'更直观的解释是:(lldb)p/t(signedchar)7(BOOL)$0=0b00000111(YES)(lldb)p/t(bool)7(bool)$1=0b000 00001(YES)32-bit版本的BOOL包括了256个值的可能性,还会引起一些坑,像这篇文章所说的。
而64-bit下只有0(NO),1(YES)两种可能,终于给BOOL正了名。
不直接取isa指针编译器已经默认禁用了这种使用,isa 指针在32位下是Class的地址,但在64位下利用bits mask才能取出来真正的地址,若真需要,使用runtime的object_getClass 和object_setClass方法。
关于64位下isa的讲解可以看这篇文章解决第三方lib依赖和lipo命令以源码形式出现在工程中的第三方lib,只要把target加上arm64编译就好了。
恶心的就是直接拖进工程的那些静态库(.a)或者framework,就需要重新找支持64-bit的包了。
这时候就能看出哪些是已无人维护的lib了,是时候找个替代品了(比如我全网找不到工程中用到的一个音频库的64位包,终于在一个哥们的github上找到,哭着给了个star- -)打印Mach-O文件支持的架构如何看一个可执行文件是不是支持64-bit呢?使用lipo -info命令,比如看看UIKit支持的架构://当前在XcodeFrameworks目录sunnyxx$lipo-infoUIKit.framework/UIKitAr chitecturesinthefatfile:UIKit.framework/UI Kitare:arm64armv7s想看的更详细的信息可以使用lipo -detailed_info:sunnyxx$lipo-detailed_infoUIKit.framew ork/UIKitFatheaderin:UIKit.framework/UI Kitfat_magic0xcafebabenfat_arch2archite cturearm64cputypeCPU_TYPE_ARM64cpu subtypeCPU_SUBTYPE_ARM64_ALLoffset4 096size16822272align2(4096)architecturearmv7scputypeCPU_TY PE_ARMcpusubtypeCPU_SUBTYPE_ARM_ V7Soffset16826368size14499840align2(4096)当然,还可以使用file命令:sunnyxx$fileUIKit.framework/UIKitUIKit.f ramework/UIKit:Mach-Ouniversalbinarywi th2architecturesUIKit.framework/UIKit(for architecturearm64):Mach-O64-bitdynamic allylinkedsharedlibraryUIKit.framework/UI Kit(forarchitecturearmv7s):Mach-Odynami callylinkedsharedlibraryarm上述命令对Mach-O文件适用,静态库.a文件,framework中的.a文件,自己app的可执行文件都可以打印下看看。
合并多个架构的包如果,我们有MyLib-32.a和MyLib-64.a,可以使用lipo -create命令合并:sunnyxx$lipo-createMyLib-32.aMyLib-64. a-outputMyLib.a支持64-bit后程序包会变大么?会,支持64-bit后,多了一个arm64架构,理论上每个架构一套指令,但相比原来会大多少还不好说,我们这里增加了大概50%,还有听说会增加一倍的。
一个lib包含了很多的架构,会打到最后的包里么?不会,如果lib中有armv7, armv7s, arm64, i386架构,而target architecture 选择了armv7s, arm64,那么只会从lib 中link指定的这两个架构的二进制代码,其他架构下的代码不会link到最终可执行文件中;反过来,一个lib需要在模拟器环境中正常link,也得包含i386架构的指令。
Checklist最后列一下官方文档中的注意点:不要将指针强转成整数程序各处使用统一的数据类型对不同类型的整数做运算时一定要注意需要定长变量时,使用如int32_t, int64_t这种定长类型使用malloc时,不要写死size使用能同时适配两个架构的格式化字符串注意函数和函数指针(类型转换和可变参数)不要直接访问Objective-C的指针(isa)使用内建的同步原语(Primitives)不要硬编码虚存页大小Go Position IndependentReferenceshttps:///library/prer elease/ios/documentation/General/Conce ptual/CocoaTouch64BitGuide/Introductio n/Introduction.html#//apple_ref/doc/uid/ TP40013501-CH1-SW1/blog/arc hive/2013/09/24/objc_explain_Non-pointer _isa.html/blog/64-b it-smorgasbord//blog/boo ls-sharp-corners/<a href="">ios消息推送</a>。