
Hallo! In dieser Mini-Artikelserie lernen Sie:
Wie erbe ich eine Swift-Klasse nicht vollstÀndig, sondern nur das, was Sie darin benötigen?
Wie können Sie den Benutzer Ihrer CocoaPods- oder Karthago-Bibliothek nur die Teile davon kompilieren lassen, die er tatsÀchlich verwendet?
Wie kann man iOS-Ressourcen zerreiĂen, um von dort aus bestimmte Systemsymbole und lokalisierte Zeichenfolgen zu erhalten?
Wie kann ich Abschlussblöcke unterstĂŒtzen, auch wenn sie nicht von der Standard-Systemberechtigungs-API bereitgestellt werden?

, , 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
Das ist alles fĂŒr jetzt
Im nĂ€chsten Teil werden wir darĂŒber sprechen, wie ich die lokalisierten Zeichenfolgen gefunden habe, die ich unter den 5 Gigabyte von iOS 14 benötigte, und wie ich die Symbole aller Systemberechtigungen erhalten habe. AuĂerdem erklĂ€re ich Ihnen, wie ich es geschafft habe, es abzulegen, requestAccess(completion:)
selbst wenn die Standard-Systemberechtigungs-API keine RĂŒckrufe unterstĂŒtzt.
Vielen Dank fĂŒr Ihre Aufmerksamkeit!