Skip to content

Commit bbb6b27

Browse files
committed
update
1 parent 8ad6089 commit bbb6b27

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

iOS/Swift/debug.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## Swift 调试
2+
3+
## lldb
4+
OC 代码中可以很方便的直接通过发消息的方式调用私有方法,但 Swift 中却因为静态语言的原因无法直接通过类似 OC 中发消息的方式调用私有方法,但 apple 对 Swift 保留了通过 `perform` 的方式,可以直接通过传入私有方法字符串的方式调用。
5+
6+
```shell
7+
(lldb) po pipController.perform("_ivarDescription")
8+
```
9+
10+
```oc
11+
[foo _ivarDescription]; // 列举了所有的实例变量、类型和值。
12+
[foo _methodDescription]; // 大致和_shortMethodDesctiption一样,但是更加详细还包含了超类的方法;
13+
[foo _shortMethodDescription]; // 列举了所有实例和类方法;
14+
```

iOS/Swift/tips.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## 小功能实现细节
2+
3+
## 悬浮窗口
4+
类似网易云桌面悬浮单词,本质上都是基于画中画做的,第一种方案是把 view 转视频,按时塞帧,第二种方案是直接获取 pip window 贴自定义 view。
5+
6+
可见:[https://github.com/CaiWanFeng/PiP](https://github.com/CaiWanFeng/PiP)
7+
8+
## 防录屏
9+
系统提供的截图和录屏的通知都是结束之后的。
10+
11+
最佳方案是 DRM,但本地 DRM 太复杂了,而且成本比较大。
12+
13+
目前看了几个投机取巧的方案都是基于 UITextField 开启 isSecureTextEntry 后拿私有视图 _UITextFieldCanvasView 做的,太 trick 了,还在找有没有牛逼的方案
14+
15+
基于 _UITextFieldCanvasView 可见:https://blog.wyan.vip/2024/02/iOS_avoid_screen_capture.html
16+
17+
但系统又提供了 `UIScreen.capturedDidChangeNotification` 这个通知,可以直接拿到是否在录屏时机,且从 iOS 11 开始支持。
18+
19+
```swift
20+
NotificationCenter.default.addObserver(self, selector: #selector(screenCaptureChanged), name: UIScreen.capturedDidChangeNotification, object: nil)
21+
22+
@objc func screenCaptureChanged(notifi: Notification) {
23+
if let screen = view.window?.windowScene?.screen, screen.isCaptured {
24+
captureView.isHidden = false
25+
} else {
26+
captureView.isHidden = true
27+
}
28+
}
29+
```
30+
31+
32+
## 防截图
33+
方案一:监听 UIApplicationUserDidTakeScreenshotNotification 通知,然后去删相册里最新的一张照片,需要相册访问权限。这方案肯定不行。

0 commit comments

Comments
 (0)