Alex Lin's Notes

Strategy, Execution, Communication.

蓝牙(Bluetooth)

去App Store搜索并下载『LightBlue』这个App,对调试你的app和理解Core Bluetooth会很有帮助。

蓝牙常见名称和缩写

  • MFI —— make for ipad ,iphone, itouch 专门为苹果设备制作的设备
  • BLE —— buletouch low energy,蓝牙4.0设备因为低耗电,所以也叫做BLE
  • peripheral,central —— 外设和中心,发起连接的设备为central,被连接的设备为perilheral
  • service and characteristic —— 服务和特征,每个设备会提供服务和特征,类似于服务端的api,但是机构不同。每个设备都会有一些服务,每个服务里面都会有一些特征,特征就是具体键值对,提供数据的地方。每个特征属性分为这么几种:读,写,通知三种方式。
  • Description —— 每个characteristic可以对应一个或多个Description用户描述characteristic的信息或属性

MFI —— 开发使用ExternalAccessory 框架

4.0 BLE —— 开发使用CoreBluetooth 框架

阅读全文 »

iOS代码签入前检查清单

iOS Pre-Check-in Checklist Yes/No
Have I regression tested everything in Instruments for leaks and abandoned memory?
Have I ran all automated UI tests and verified there are no crash bugs?
Have I ran all unit tests to insure I haven’t broken anything?
Did I do a compare of all the code to make sure all code is code review ready?
Have all new files been added into source control?
Have all work items been updated and ready to associate with the check-in?
Have I removed all code I commented out that no longer needs to be there?
Have I written clean code comments?
Is there anything I hacked together quickly to get it to work but needs to be cleaned up?
Is there duplicate code that I could simplify into 1 location?
Is there debug code that needs to be removed or commented out?
Is all text localized for all supported languages?
Are all images provided by the graphic designer checked in?
Are there any warnings in the checked-out files that can be addressed in this check-in?
Are there new dev target/environment settings that I forgot to also add to the production target/environment?
  1. 是否在Instruments中对内存泄露进行了回归测试?

    Have I regression tested everything in Instruments for leaks and abandoned memory?

  2. 是否运行了所有的UI测试同时确认没有crash bugs?

    Have I ran all automated UI tests and verified there are no crash bugs?

  3. 是否运行了所有的单元测试确保没有造成破坏?

    Have I ran all unit tests to insure I haven’t broken anything?

  4. 是否进行了所有代码比较确保所有代码审查准备好了?

    Did I do a compare of all the code to make sure all code is code review ready?

  5. 是否所有新文件都添加到源代码管理中?

    Have all new files been added into source control?

  6. 是否所有工作项已经被更新并准备签入?

    Have all work items been updated and ready to associate with the check-in?

  7. 是否移除了已经注释过不再使用的代码?

    Have I removed all code I commented out that no longer needs to be there?

  8. 是否写了清晰的代码注释?

    Have I written clean code comments?

  9. 是否有某个功能是仅仅为了让程序能迅速运行但是需要清除的(比如某段没有设计过的功能代码)?

    Is there anything I hacked together quickly to get it to work but needs to be cleaned up?

  10. 是否有可以简化的重复代码?

    Is there duplicate code that I could simplify into 1 location?

  11. 是否有需要移除或者注释掉的调试代码?

    Is there debug code that needs to be removed or commented out?

  12. 是否所有支持多语言的文本都已经本地化?

    Is all text localized for all supported languages?

  13. 是否由图形设计师提供的图片都已经签入?

    Are all images provided by the graphic designer checked in?

  14. 是否在本次签入代码之前能够解决检出代码的警告?

    Are there any warnings in the checked-out files that can be addressed in this check-in?​

  15. 是否有新的开发的target/environment设置忘了添加到生产的 target/environment?

    Are there new dev target/environment settings that I forgot to also add to the production target/environment?

iOS 测试清单

Final Sanity Checks Appearance Functionality
Localized? YES NO
Portrait/Landscape?
Empty Data Source?
Large Data Source?
CRUD?
All modes/perspectives?
Different Entry/Exit points?
Different User Settings?
Without internet connection?
iPhone & iPad? (if Universal)
New Install?
Different version of iOS?

二维码

扫描识别

iOS中实现二维码和条形码扫描,两大开源组件 ZBarSDK 与 ZXing以及AVFoundation。AVFoundation.framework(iOS 7 )之后才添加了二维码扫描的功能。

二维码生成

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- (UIImage *)qrCodeGenerator:(NSString *)msg size:(CGSize)size {
NSData * data = [msg dataUsingEncoding:NSUTF8StringEncoding];

NSDictionary * params = @{@"inputMessage": data, @"inputCorrectionLevel": @"H"};
CIFilter * qrEncoder = [CIFilter filterWithName:@"CIQRCodeGenerator" withInputParameters:params];
CIImage * ciImage = qrEncoder.outputImage;
UIImage * qrImage = [UIImage imageWithCIImage:ciImage];

UIGraphicsBeginImageContext(size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetInterpolationQuality(context, kCGInterpolationNone);
[qrImage drawInRect:CGRectMake(0, 0, size.width, size.height)];
qrImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return qrImage;
}

Demo下载QRCodeScanner

阅读全文 »

UIScrollView中子视图建立约束不能实现滚动,要实现子视图的AutoLayout布局需要借助UIView来实现。

具体实现步骤

  1. 添加一个UIView作为UIScrollView的ContentView,之后将之前直接添加到UIScrollView中的子视图添加到ContentView中
  2. 为ContentView建立6个约束,四条边的约束、高度和宽度的约束。
  3. 若要实现UIScrollView垂直滚动修改Equal Height约束的优先级为Low(250),若要实现UIScrollView水平滚动修改Equal Width约束的优先级为Low(250)
  4. 将原本添加到UIScrollView中的子视图添加到ContentView,为子视图建立约束
  5. 若是垂直滚动,需要为最下方的子视图添加一个Bottom Space to SuperView约束;若是水平滚动,需要设置最右方的子视图添加一个Trailing space to SuperView约束
  6. 最终实现在UIScrollView的子视图通过AutoLayout布局实现滚动效果

Demo 下载

https://github.com/xwal/Demo/tree/master/UIScrollViewAutoLayout

iOS网络编程层次结构

iOS网络编程层次结构分为三层,从上往下依次为:

  • Cocoa层:NSURL,Bonjour,Game Kit,WebKit
  • Core Foundation层:基于 C 的 CFNetwork 和 CFNetServices
  • OS层:基于 C 的 BSD Socket

Cocoa层:是最上层的基于 Objective-C 的 API,比如 URL访问,NSStream,Bonjour,GameKit等,这是大多数情况下我们常用的 API。Cocoa 层是基于 Core Foundation 实现的。

Core Foundation层:因为直接使用 socket 需要更多的编程工作,所以苹果对 OS 层的 socket 进行简单的封装以简化编程任务。该层提供了 CFNetwork 和 CFNetServices,其中 CFNetwork 又是基于 CFStream 和 CFSocket。

OS层:最底层的 BSD Socket 提供了对网络编程最大程度的控制,但是编程工作也是最多的。因此,苹果建议我们使用 Core Foundation 及以上层的 API 进行编程。

本文将介绍如何在 iOS 系统下使用最底层的 Socket 进行编程。

阅读全文 »

iOS支付分为两类,第三方支付应用内支付(内购)

第三方支付包括:支付宝支付、微信支付、银联支付、百度钱包、京东支付等等。

应用内支付(In-App Purchase):在应用程序内购买虚拟商品。如果你在App Store上销售的应用程序,将收到支付金额的70%。

阅读全文 »

推送通知是当程序没有启动或不在前台运行时,告诉用户有新消息的一种途径。

有远程推送和本地推送之分。

阅读全文 »

目录结构

一个合理的目录结构首先应该是清晰的,让人一眼看上去就能大概了解目录的职责,且容易应对新的变化。

常规的两种结构:

  1. 主目录按照业务分类,内目录按照模块分类(主目录按照MVC架构分类,内部根据项目模块分类)

    优点:相对比较快定位对应的业务。
    缺点:模块相关类太过分散,需要来回切换寻找文件,不方便开发。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    ├── Application
    ├── Categories
    ├── Controllers
    │   ├── Blog
    │   ├── Comment
    │   ├── Login
    │   ├── News
    | ...
    ├── Models
    │   ├── OSC
    │   └── Team
    ├── Resource
    │   ├── CSS
    │   ├── html
    │   ├── js
    ├── Utils
    ├── Vendor
    └── Views
  2. 主目录按照模块分类,内目录按照业务分类

    优点:对模块的类集中化,方便管理与开发。
    缺点:当几个模块共用一些类时,不太好归类。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    ├── Application
    ├── Categories
    │├── Blog
    | ├── Controller
    | ├── View
    | ├── Model
    ├── Login
    | ├── Controller
    | ├── View
    | ├── Model
    | ....
    ├── Resource
    │   ├── CSS
    │   ├── html
    │   ├── js
    ├── Utils
    ├── Vendor
阅读全文 »

开发社区

  1. iOS 开源代码库 http://www.code4app.com/
  2. 苹果开发中文社区 http://www.cocoachina.com/
  3. Github https://github.com
  4. ObjC 中国 http://objccn.io/
  5. 歪果仁教程:Ray Wenderlich | Tutorials for iPhone / iOS Developers and Gamers http://www.raywenderlich.com/
  6. 开发者头条,各类技术干货 http://toutiao.io

开源项目

  1. YY作者常用第三方库整理 http://github.ibireme.com/github/list/ios/
  2. 最全开源项目和学习资料 http://codecloud.net/ios-mac-study-5155.html
  3. 常用库整理 http://www.cocoachina.com/ios/20150713/12503.html
  4. 歪果仁整理的关于iOS开发技术 https://github.com/vsouza/awesome-ios
  5. iOS开发UI https://github.com/cjwirth/awesome-ios-ui
0%