Halo! Dalam artikel seri mini ini, Anda akan mempelajari:
Bagaimana cara mewarisi kelas Swift tidak sepenuhnya, tetapi hanya yang Anda butuhkan di dalamnya?
Bagaimana Anda mengizinkan pengguna pustaka CocoaPods atau Carthage Anda hanya mengompilasi bagian-bagian yang sebenarnya mereka gunakan?
Bagaimana cara merobek sumber daya iOS untuk mendapatkan ikon sistem tertentu dan string yang dilokalkan dari sana?
Bagaimana cara mendukung blok penyelesaian meskipun tidak disediakan oleh API izin sistem default?
, , iOS — . , !
— . ? . ? .
Apple, Stack Overflow. , , - .
GitHub , , . , — , - , .
. . , , . , PermissionWizard...
iOS 14 macOS 11 Big Sur
Mac Catalyst
«Info.plist» , -
, API
, - , , ,
DispatchQueue.main
Swift
API ,
UI
, ,
- ...
, , ?
PermissionWizard, , :
usageDescriptionPlistKey
checkStatus
requestAccess
, , , .
, , , Swift Xcode , — .
, :
(, ) , ,
checkStatus
. — , .
requestAccess(completion:)
, , , .requestAccess(whenInUseOnly:completion:)
, - , .
plist- — (NSPhotoLibraryUsageDescription) , (NSPhotoLibraryAddUsageDescription). , -
usageDescriptionPlistKey
— .
. . , 18 , , .
-. , . , — .
class SupportedType {
func requestAccess(completion: (Status) -> Void) { }
}
final class Bluetooth: SupportedType { ... }
final class Location: SupportedType {
@available(*, unavailable)
override func requestAccess(completion: (Status) -> Void) { }
func requestAccess(whenInUseOnly: Bool, completion: (Status) -> Void) { ... }
}
, @available(*, unavailable)
, , , Xcode, .
, , , .
CocoaPods- Carthage- , ?
PermissionWizard 18 — Siri iOS 14 . , AVKit, CoreBluetooth, CoreLocation, CoreMotion, EventKit, HealthKit, HomeKit .
, , - , Apple App Store, , API . , — . - .
CocoaPods
. , , . , .
pod 'PermissionWizard/Assets' # Icons and localized strings
pod 'PermissionWizard/Bluetooth'
pod 'PermissionWizard/Calendars'
pod 'PermissionWizard/Camera'
pod 'PermissionWizard/Contacts'
pod 'PermissionWizard/FaceID'
pod 'PermissionWizard/Health'
pod 'PermissionWizard/Home'
pod 'PermissionWizard/LocalNetwork'
pod 'PermissionWizard/Location'
pod 'PermissionWizard/Microphone'
pod 'PermissionWizard/Motion'
pod 'PermissionWizard/Music'
pod 'PermissionWizard/Notifications'
pod 'PermissionWizard/Photos'
pod 'PermissionWizard/Reminders'
pod 'PermissionWizard/Siri'
pod 'PermissionWizard/SpeechRecognition'
pod 'PermissionWizard/Tracking'
, «Podspec» (, CocoaPods) :
Pod::Spec.new do |spec|
...
spec.subspec 'Core' do |core|
core.source_files = 'Source/Permission.swift', 'Source/Framework'
end
spec.subspec 'Assets' do |assets|
assets.dependency 'PermissionWizard/Core'
assets.pod_target_xcconfig = { 'SWIFT_ACTIVE_COMPILATION_CONDITIONS' => 'ASSETS' }
assets.resource_bundles = {
'Icons' => 'Source/Icons.xcassets',
'Localizations' => 'Source/Localizations/*.lproj'
}
end
spec.subspec 'Bluetooth' do |bluetooth|
bluetooth.dependency 'PermissionWizard/Core'
bluetooth.pod_target_xcconfig = { 'SWIFT_ACTIVE_COMPILATION_CONDITIONS' => 'BLUETOOTH' }
bluetooth.source_files = 'Source/Supported Types/Bluetooth*.swift'
end
...
spec.default_subspec = 'Assets', 'Bluetooth', 'Calendars', 'Camera', 'Contacts', 'FaceID', 'Health', 'Home', 'LocalNetwork', 'Location', 'Microphone', 'Motion', 'Music', 'Notifications', 'Photos', 'Reminders', 'Siri', 'SpeechRecognition', 'Tracking'
end
, , .
#if BLUETOOTH
final class Bluetooth { ... }
#endif
Carthage
. , - — , . , - .
«Settings.xcconfig» :
#include? "../../../../PermissionWizard.xcconfig"
Carthage «Carthage/Build/iOS», «PermissionWizard.xcconfig», .
:
ENABLED_FEATURES = ASSETS BLUETOOTH ... SWIFT_ACTIVE_COMPILATION_CONDITIONS = $(inherited) $(ENABLED_FEATURES) CUSTOM_SETTINGS
, , «Settings.xcconfig» . , , «project.pbxproj» . , , .
A53DFF50255AAB8200995A85 /* Settings.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Settings.xcconfig; sourceTree = "<group>"; };
«XCBuildConfiguration» ( 3):
B6DAF0412528D771002483A6 /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = A53DFF50255AAB8200995A85 /* Settings.xcconfig */;
buildSettings = {
...
};
name = Release;
};
, CUSTOM_SETTINGS
. — , , «PermissionWizard.xcconfig» , .
#if BLUETOOTH || !CUSTOM_SETTINGS
final class Bluetooth { ... }
#endif
Itu saja untuk saat ini
Di bagian selanjutnya, kita akan berbicara tentang bagaimana saya menemukan string terlokalisasi yang saya butuhkan di antara 5 gigabyte iOS 14 dan bagaimana saya mendapatkan ikon dari semua izin sistem. Dan saya juga akan memberi tahu Anda bagaimana saya berhasil mengajukannya requestAccess(completion:)
meskipun API izin sistem default tidak mendukung callback.
Terima kasih atas perhatiannya!