Light's Blog

The best or nothing.

ReactiveObjC Memory Management

| Comments

You don’t need to retain signals in order to process them.

Subscribers

Any objects referenced from those blocks will therefore be retained as part of the subscription.

Finite or Short-Lived Signals

Subscription is automatically terminated upon completion or error, and the subscriber removed.
The RACSignal -> RACSubscriber relationship is torn down as soon as signal finishes, breaking the retain cycle.

ReactiveObjC Framework Overview

| Comments

Streams

A stream, represented by the RACStream abstract class, is any series of object values.

Signals

A signal, represented by the RACSignal class, is a push-driven stream.

Signals generally represent data that will be delivered in the future. Users must subscribe to a signal in order to access its values.

Signals send three different types of events to their subscribers:

  1. The next event provides a new value from the stream.
  2. The error event indicates that an error occurred before the signal could finish.
  3. The completed event indicates that the signal finished successfully, and that no more values will be added to the stream.

iOS知识小集-170925

| Comments

URL encode

string -> url,特殊字符需要编码。

1
2
3
4
- (NSString *)urlEncode:(NSString *)string {
  NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInString:@";/?:@=&<>\"#%{}|\\^~[]` ()"].invertedSet;
  return [string stringByAddingPercentEncodingWithAllowedCharacters:set];
}

iOS知识小集-170918

| Comments

UIButton Gestures

UIControlEventTouchDown:按下button;
UIControlEventTouchDragExit:拖动至button范围(button四周有一定范围)外;
UIControlEventTouchDragEnter:拖动至button范围(button四周有一定范围)内。
UIControlEventTouchUpInside:在button内松手;
UIControlEventTouchUpOutside:在button外松手;
UIControlEventTouchDragOutside:在button外拖动。
UIControlEventTouchDragInside:在button内拖动;
UIControlEventTouchCancel:系统行为取消touch;

iOS知识小集-170911

| Comments

长按语音控制

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
-(void)setupBtn{
  //  按下按钮
  [self.voiceBtn addTarget:self action:@selector(btnTouchBegin:) forControlEvents:UIControlEventTouchDown];
  //  立刻松开
  [self.voiceBtn addTarget:self action:@selector(btnTouchEnd:) forControlEvents:UIControlEventTouchUpInside];
  //  上划取消
  [self.voiceBtn addTarget:self action:@selector(cancelSpeak) forControlEvents:UIControlEventTouchDragExit];
  //  外部松开
  [self.voiceBtn addTarget:self action:@selector(btnTouchEnd:) forControlEvents:UIControlEventTouchUpOutside];
}

//  通过计时器区分“点击”还是“长按”
- (void)btnTouchBegin:(UIButton *)button {
  self.countNum = 0.0f;
  self.timer =
      [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(handleTimer) userInfo:nil repeats:YES];
  [self.timer fire];
}

- (void)btnTouchEnd:(UIButton *)button {
  [self.timer invalidate];

  if ([self isLongPressGesture]) {
    //  执行长按操作
  } else {
    //  执行点击操作
  }
}

// 处理时间
- (void)handleTimer {
  self.countNum += 0.1;

  if ([self isLongPressGesture]) {
    [self.timer invalidate];
    [self longPressVoiceBegin];
  }
}

// 判断是否为长按手势
- (BOOL)isLongPressGesture {
  return self.countNum >= 0.5;
}

// 上划取消语音输入
- (void)cancelSpeak {
  [self voiceEnd];
}

iOS知识小集-170828

| Comments

TableView Header / Footer Height

UITableView默认有section header/footer高度,设为0无效,最小可设为1。

CNContactPickerViewController

1
2
3
4
5
6
7
8
9
10
11
12
13
14
-(void)pickContact{
  CNContactPickerViewController *controller = [[CNContactPickerViewController alloc] init];
  controller.delegate = self;
  [self presentViewController:controller animated:YES completion:nil];
}

- (void)contactPicker:(CNContactPickerViewController *)picker
    didSelectContactProperty:(CNContactProperty *)contactProperty {
  CNContact *contact = contactProperty.contact;
  NSString *name = [CNContactFormatter stringFromContact:contact style:CNContactFormatterStyleFullName];
  CNPhoneNumber *phoneValue = contactProperty.value;
  NSString *phoneNumber = phoneValue.stringValue;
  NSLog(@"%@--%@", name, phoneNumber);
}

iOS知识小集-170821

| Comments

ipa架构

IPA File
  Payload
    {appname}.app
      Application Binary
      Mobile Provision File
      Code Signature
      Bundled Resource File
  iTunesArtwork
  iTunesMetadata.plist

iOS知识小集-170814

| Comments

使用Xcode查看代码作者和提交信息

切换为“Blame”和“Log”模式即可。

AVAudioSession

AVAudioSessionCategoryOptionDefaultToSpeaker:通过扬声器播放声音。
AVAudioSessionCategoryOptionMixWithOthers:不打断其他App音频播放。

JSONModel

下划线key转驼峰key。 [JSONKeyMapper mapperFromUnderscoreCaseToCamelCase]已废弃, 现在使用[JSONKeyMapper mapperForSnakeCase]

Acoustic Echo Cancellation

Audio Unit回声消除。