Dear all,
I have developed an iOS application named “MMWSwift” to let the user interact with a number of Photons used for various domotica tasks using the iOS SDK package. My program was originally written in Swift 2 and has functioned without any problems.
After upgrading to iOS 10 / Xcode 8.0 / Swift 3 my application, crashes when calling the Particle cloud login function. I have converted all my application Swift 2 source code to Swift 3 and Xcode compiles and builds the converted program with no errors or warnings. But as soon as the application tries to log into the Particle cloud the program crashes.
My podfile contains the following lines:
target 'MMWswift' do
pod 'Spark-SDK'
end
I have run the ‘pod update’ command in order to use the latest version of the Spark-SDK and AFNetworking libraries, getting the following output message:
Update all pods
Updating local specs repositories
CocoaPods 1.1.0.rc.2 is available.
To update use: `sudo gem install cocoapods --pre`
[!] This is a test version we'd love you to try.
For more information, see https://blog.cocoapods.org and the CHANGELOG for this version at https://github.com/CocoaPods/CocoaPods/releases/tag/1.1.0.rc.2
Analyzing dependencies
Downloading dependencies
Using AFNetworking (3.1.0)
Using Spark-SDK (0.5.1)
Generating Pods project
Integrating client project
Pod installation complete! There is 1 dependency from the Podfile and 2 total
pods installed.
My initial Swift (2) code that ran without problems was:
SparkCloud.sharedInstance().loginWithUser("username@email.com", password: "userpass") { (error:NSError?) -> Void in
if let e=error {
println("Wrong credentials or no internet connectivity, please try again")
}
else {
println("Logged in")
}
}
After converting to Swift 3 my code is:
SparkCloud.sharedInstance().login(withUser: "username@email.com", password: "userpass") { (error:Error?) -> Void in
if let _ = error {
print("Wrong credentials or no internet connectivity, please try again")
}
else {
print("Logged in")
}
}
I have set a breakpoint on the first line of this code. The program runs to this point with no problems but crashes immediately when the Xcode debugger is trying to proceed any further. The debugger produces the following messages:
2016-09-16 11:31:52.501 MMWswift[4292:268166] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Couldn't add the Keychain Item.'
*** First throw call stack:
(
0 CoreFoundation 0x00000001055af34b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010501021e objc_exception_throw + 48
2 CoreFoundation 0x00000001055b3442 +[NSException raise:format:arguments:] + 98
3 Foundation 0x0000000104ba6edd -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
4 MMWswift 0x0000000103ee446a -[KeychainItemWrapper writeToKeychain] + 970
5 MMWswift 0x0000000103ee396a -[KeychainItemWrapper setObject:forKey:] + 218
6 MMWswift 0x0000000103ef8ac2 -[SparkSession storeSessionInKeychainAndSetExpiryTimer] + 1234
7 MMWswift 0x0000000103ef8408 -[SparkSession initWithNewSession:] + 1016
8 MMWswift 0x0000000103ee62e0 __48-[SparkCloud loginWithUser:password:completion:]_block_invoke + 208
9 MMWswift 0x0000000103eac504 __116-[AFHTTPSessionManager dataTaskWithHTTPMethod:URLString:parameters:uploadProgress:downloadProgress:success:failure:]_block_invoke.97 + 228
10 MMWswift 0x0000000103ecf099 __72-[AFURLSessionManagerTaskDelegate URLSession:task:didCompleteWithError:]_block_invoke_2.150 + 201
11 libdispatch.dylib 0x0000000108bf6980 _dispatch_call_block_and_release + 12
12 libdispatch.dylib 0x0000000108c200cd _dispatch_client_callout + 8
13 libdispatch.dylib 0x0000000108c00a1d _dispatch_main_queue_callback_4CF + 733
14 CoreFoundation 0x00000001055734f9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
15 CoreFoundation 0x0000000105538f8d __CFRunLoopRun + 2205
16 CoreFoundation 0x0000000105538494 CFRunLoopRunSpecific + 420
17 GraphicsServices 0x000000010b243a6f GSEventRunModal + 161
18 UIKit 0x0000000105f8cf34 UIApplicationMain + 159
19 MMWswift 0x0000000103e902cf main + 111
20 libdyld.dylib 0x0000000108c6c68d start + 1
21 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I do not know if the underlying problem causing the crash is in the Spark-SDK library or in the AFNetworking library or in my line of code (see above) that calls the Spark Cloud login function.
Has anyone experienced a similar problem and could you tell me how you solved it?
Thanks in advance!