1. 读取剪切板自动提示用户
2. 使用相机和麦克风自动提示用户
3. 定位精度
private lazy var locationManager: CLLocationManager = {
let manager = CLLocationManager()
manager.delegate = self
return manager
}()
private func start() {
if #available(iOS 14.0, *) {
if locationManager.accuracyAuthorization == .reducedAccuracy {
// 如果没有精准定位,可以向用户临时申请给一次精准定位的机会
// 这个key其实是想获取定义在info.plist的键Privacy - Location Temporary Usage Description Dictionary中
// 设置的提示,为什么需要获取精准定位?
locationManager.requestTemporaryFullAccuracyAuthorization(withPurposeKey: "deliver")
}
}
locationManager.requestAlwaysAuthorization()
locationManager.startUpdatingLocation()
}
3.1 强制只获取默认地址
4. Limited Photo
4.1 默认选择图片方式
iOS13以下选取图片
let picker = UIImagePickerController()
picker.delegate = self
present(picker, animated: true, completion: nil)
iOS13及以上选取图片
/// 使用
private func picker() {
if #available(iOS 14, *) {
var configuration = PHPickerConfiguration()
configuration.selectionLimit = 9
let picker = PHPickerViewController(configuration: configuration)
picker.modalPresentationStyle = .fullScreen
picker.delegate = self
present(picker, animated: true, completion: nil)
} else {
// Fallback on earlier versions
}
}
@available(iOS 14, *)
func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
print(results.count)
print(results)
}
4.2 写入图片至相册
private func write() {
UIImageWriteToSavedPhotosAlbum(imageView.image!, nil, nil, nil)
}