移动周分享-第50期

先看命令帮助的讲解 - 王胜

1
2
3
4
5
6
7
8
9
10
11
12
13
Victors-MPB:hello wangsheng$ git reset -h
usage: git reset [--mixed | --soft | --hard | --merge | --keep] [-q] [<commit>]
or: git reset [-q] <tree-ish> [--] <paths>...
or: git reset --patch [<tree-ish>] [--] [<paths>...]

-q, --quiet be quiet, only report errors
--mixed reset HEAD and index
--soft reset only HEAD
--hard reset HEAD, index and working tree
--merge reset HEAD, index and working tree
--keep reset HEAD but keep local changes
-p, --patch select hunks interactively
-N, --intent-to-add record only the fact that removed paths will be added later

各种模式对比

模式 HEAD是否重置 Index是否重置 working区是否重置
—mixed『缺省模式』
—soft
—hard
—merge
—keep

SourceTree 重置分析

重置 -> 丢弃文件变更

  • 操作截图

    git-reset-mixed-partial

  • 实际执行的命令

1
2
3
git -c diff.mnemonicprefix=false -c core.quotepath=false -c credential.helper=sourcetree reset -q HEAD -- a.txt c.txt 	
git -c diff.mnemonicprefix=false -c core.quotepath=false -c credential.helper=sourcetree checkout HEAD -- a.txt
Completed successfully
  • 结果
1
2
3
4
5
6
7
8
9
10
11
Victors-MPB:hello wangsheng$ git st
On branch feature2
All conflicts fixed but you are still merging.
(use "git commit" to conclude merge)

Untracked files:
(use "git add <file>..." to include in what will be committed)

c.txt

nothing added to commit but untracked files present (use "git add" to track)

可以看出这样操作,git的上下文环境还在merge状态,这种情况一不小心就容易当做重置干净了,继续干自己的事情了,殊不知把别人的改动丢弃了。

重置 -> 重置所有

  • 操作截图

    git-reset-hard-all

  • 实际执行的命令

1
2
3
4
git -c diff.mnemonicprefix=false -c core.quotepath=false -c credential.helper=sourcetree reset -q --hard HEAD -- 

git -c diff.mnemonicprefix=false -c core.quotepath=false -c credential.helper=sourcetree submodule update --init --recursive
Completed successfully
  • 结果
1
2
3
Victors-MPB:hello wangsheng$ git st
On branch feature2
nothing to commit, working directory clean

快速集成TouchID - 杨志平

iPhone 5s,iOS 8,iOS7时未开放

依赖 LocalAuthentication.framework

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// 判断设备支持状态
LAContext *context = [[LAContext alloc] init];
[context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil];

// 如果可以
[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"reason" reply:^(BOOL success, NSError *error) {
if (success) {
//验证成功,主线程处理UI
}
else
{
// 重点:错误处理,分为多种错误
// 有验证失败、取消、手动输入密码等等相对应的逻辑处理
// 详见demo
}
}];

错误类型

  • LAErrorAuthenticationFailed
  • LAErrorUserCancel
  • LAErrorUserFallback
  • LAErrorSystemCancel
  • LAErrorPasscodeNotSet
  • LAErrorTouchIDNotAvailable
  • LAErrorTouchIDNotEnrolled
  • LAErrorTouchIDLockout NS_ENUM_AVAILABLE(10_11, 9_0)
  • LAErrorAppCancel NS_ENUM_AVAILABLE(10_11, 9_0)
  • LAErrorInvalidContext NS_ENUM_AVAILABLE(10_11, 9_0)

dispatch_sync的坑 - 潘君

起因

dispatch_sync自己创建的队列 仍旧有可能在main thread上执行block

  • GCD只是管理一个线程池 不保证一定在某一个thread或不在某一个thread执行

  • 非main程队列也有可能调用主线程

  • 为了优化 有可能在当前线程中执行block

问题

如何不让dispatch_sync卡主线程呢

答: 别在主线程调用此函数 哈哈哈

用途

  • 锁的功能

  • 确保在主线程执行block

AFNetworking在调用前判断是否是主线程

1
2
3
4
5
6
7
8
9
10
11
12

if (![[NSThread currentThread] isMainThread]) {

dispatch_sync(dispatch_get_main_queue(), ^{

[self transitionToNextPhase];

});

return YES;

}

参考