I've just started using CryptoKit to replace an old library. My plan was to replace it on phones running iOS 13 and above, and still use the old library on iOS versions below 13. However I can't get the app to even start in iOS 12.4 without crashing. I've removed everything else and only att these simple lines
if #available(iOS 13.0, *) {
let nonce = try? AES.GCM.Nonce(data: iv)
}
The #available
I thought was used to make sure that is was skipped if the condition wasn't fulfilled.
The stranger part is that the app crashes without me ever calling the meshing containing these lines, just having them somewhere in the app causes it to crash.
I have also imported CryptoKit at the top (with and without if canImport(CryptoKit)
) and I have added @available(iOS 13.0, *)
to the class.
Can anyone tell me the correct way to "exclude" the code, or whatever the correct way is, for lower iOS-versions. I guess it must be possible to use iOS 13-specific functionality while still maintaining backwards-compability through "old" methods?
Also, I'm using Xcode 11, but I guess that may be obvious.
And the error I'm getting is:
dyld: Library not loaded: /System/Library/Frameworks/CryptoKit.framework/CryptoKit
EDIT: Now I've also tried putting this around the entire class (including the import)
#if canImport(CryptoKit)
#endif
And also, I've notices that this line can exist without crashing the app:
let key = SymmetricKey(data: Data())
And symmetric key is also part of CryptoKit
EDIT 2: I've figured out that weak linking would solve the problem. I tried using one of the other new (iOS 13) frameworks, CryptoTokenKit, and had the same problem. But here I could add the framework and set the linking to optional, which solved the problem. However when adding frameworks to the app CryptoKit is not available for some reason.
CryptoKit
framework to your project? Did you add it as a dependency in the project settings? – Leffenimport CryptoKit
at the top of the file. CryptoKit is native from Apple since iOS 13. Do I still need to add it somehow? – Temporal