jrendel / SwiftKeychainWrapper

A simple wrapper for the iOS Keychain to allow you to use it in a similar fashion to User Defaults. Written in Swift.
MIT License
1.59k stars 339 forks source link

xCode8 with Swift2.3 returns false #62

Closed kristijanexads closed 7 years ago

kristijanexads commented 7 years ago

Hi @jrendel , I have a problem with saving values to Keychain, below is the line I'm using, and it always returns false in xCode8 and Swift2.3 (I can't use Swift 3 at the moment because some other frameworks are not updated) Just to mention, it all worked with xCode7 and Swift2.2 on iOS9.3 simulator, but now I'm using iOS10 simulator, maybe this could be the issue? (downloading 9.3 simulators at the moment)

let isSaveSuccessfulToken: Bool = KeychainWrapper.defaultKeychainWrapper().setString(token, forKey: "token")

I'm using Carthage and I tried with the following
github "jrendel/SwiftKeychainWrapper" github "jrendel/SwiftKeychainWrapper" "master" github "jrendel/SwiftKeychainWrapper" == 2.1.0 github "jrendel/SwiftKeychainWrapper" "Swift2.3"

all compiled to Swift2.3 using carthage update --platform iOS --toolchain com.apple.dt.toolchain.Swift_2_3 SwiftKeychainWrapper which builds successfully (also used with some other frameworks that work now)

Tnx

emcphersonburke commented 7 years ago

I was experiencing the same problem, and apparently having Code Signing Entitlements will fix the issue. For me, Xcode 8 had switched off Push Notifications in the Capabilities tab. I switched that back on, Xcode automatically generated an entitlements file. Suddenly the keychain started working. If you don't have push in your project, I suspect manually adding entitlements would have the same result.

kristijanexads commented 7 years ago

@emcphersonburke just figured this out from some other post on SO. here is the link, might help someone, the part with turning Keychain Sharing ON (in the Capabilities tab)

http://stackoverflow.com/questions/38456471/secitemadd-always-returns-error-34018-in-xcode-8-in-ios-10-simulator#answers-header

emcphersonburke commented 7 years ago

@kristijanexads I noticed that as well, but didn't have any use for enabling Keychain Sharing for my app. I suspect the fix from that route is also a result of the entitlements file generated from enabling Keychain Sharing. Curious to see if this is an iOS bug or if there's some reason keychain access now seems to require the presence of an entitlements file. Any which way, I'm glad to hear it's working for you now!

kristijanexads commented 7 years ago

Well I thought that since I'm using Keychain that this option should be on, but yes, I also wander if it's a bug or keychain require the presence of an entitlements file.

jrendel commented 7 years ago

Sounds like you guys are facing the same issue I saw on the Swift 3 branch with iOS 10 simulators. I opened this issue for it: https://github.com/jrendel/SwiftKeychainWrapper/issues/59

For myself, I'm just hitting it running unit tests on the framework project itself, so don't even have the option of enabling keychain sharing as suggested in a few places. However, running unit tests against a 9.x simulator did work for me.

kristijanexads commented 7 years ago

@jrendel I hope you will find a solution for the tests, here is one reply https://forums.developer.apple.com/message/170381#181413 that mentions tests, maybe it can help you with issue #59

JRG-Developer commented 7 years ago

For myself, I'm just hitting it running unit tests on the framework project itself, so don't even have the option of enabling keychain sharing as suggested in a few places

I had this issue when running unit tests as well. As a workaround to test on the iOS 10 simulator, I created a Single View application template, added all files from the dynamic framework, and setup suggested code signing and entitlements... Ideal? Not really, but it works. :]

The CocoaPods team recommends this method for creating Swift CocoaPods... That is, Swift dynamic framework pod development/integration doesn't really work/isn't supported; see https://github.com/CocoaPods/CocoaPods/issues/5256 for more details.

Wonky? Definitely is, but Apple development frequently is. ;P

jrendel commented 7 years ago

I've done something similar now and unit tests should be working under the Swift 3.0 build in master. I will not be updating the Swift 2.3 branch with this. Xcode 8.2 is in beta and this it is the last release that will support Swift 2.x from what I understand.