Firebase Convert Anonymous to Permanent Account Error - ios

I have the user already Signed in Anonymously in my app through the following code:
Auth.auth().signInAnonymously { (result, error) in
if let error = error {
Auth.auth().handleFireAuthError(error: error, vc: self)
debugPrint(error)
}
}
Then at one point I require the user to sign up and I am using the following code to link the Anonymous account to a permanent account:
guard let email = userEmailTextField.text, email.isNotEmpty,
let password = userPasswordTextField.text, password.isNotEmpty else {
simpleAlert(title: "Error", msg: "Please fill out all fields.")
return
}
guard let confirmPass = userRepeatPasswordTextField.text , confirmPass == password else{
simpleAlert(title: "Error", msg: "Passwords do not match.")
return
}
guard let authUser = Auth.auth().currentUser else {
return
}
let credential = EmailAuthProvider.credential(withEmail: email, link: password)
authUser.link(with: credential) { (result, error) in
if let error = error {
debugPrint(error)
Auth.auth().handleFireAuthError(error: error, vc: self)
self.activityIndicator.stopAnimating()
return
}
guard let fireUser = result?.user else {return}
let artUser = User.init(id: fireUser.uid, email: email , stripeId:"")
//Upload to Firestore
self.createFirestoreUser(user: artUser)
}
But I get an error here. I put break point and this is where the execution stop authUser.link(with: credential) { (result, error) in
This is the error I am getting:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[NSURLComponents initWithString:]: nil URLString parameter'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff23e39f0e __exceptionPreprocess + 350
1 libobjc.A.dylib 0x00007fff50ad79b2 objc_exception_throw + 48
2 Foundation 0x00007fff259659ca -[__NSConcreteURLComponents URL] + 0
3 Foundation 0x00007fff259673a8 +[NSURLComponents componentsWithString:] + 33
4 Silobee 0x000000010b144c52 +[FIRAuthWebUtils parseURL:] + 98
5 Silobee 0x000000010b16c638 __56-[FIRUser linkAndRetrieveDataWithCredential:completion:]_block_invoke_3 + 440
6 Silobee 0x000000010b16b084 __51-[FIRUser internalGetTokenForcingRefresh:callback:]_block_invoke + 340
7 Silobee 0x000000010b15df8c __65-[FIRSecureTokenService fetchAccessTokenForcingRefresh:callback:]_block_invoke + 156
8 Silobee 0x000000010b13fa7b __38-[FIRAuthSerialTaskQueue enqueueTask:]_block_invoke + 155
9 libdispatch.dylib 0x0000000110850f11 _dispatch_call_block_and_release + 12
10 libdispatch.dylib 0x0000000110851e8e _dispatch_client_callout + 8
11 libdispatch.dylib 0x00000001108586fd _dispatch_lane_serial_drain + 788
12 libdispatch.dylib 0x00000001108592c5 _dispatch_lane_invoke + 476
13 libdispatch.dylib 0x000000011085851c _dispatch_lane_serial_drain + 307
14 libdispatch.dylib 0x000000011085928f _dispatch_lane_invoke + 422
15 libdispatch.dylib 0x0000000110864b65 _dispatch_workloop_worker_thread + 719
16 libsystem_pthread.dylib 0x00007fff51b37a3d _pthread_wqthread + 290
17 libsystem_pthread.dylib 0x00007fff51b36b77 start_wqthread + 15
)
libc++abi.dylib: terminating with uncaught exception of type NSException

Just saw where my problem is! Instead of this:
let credential = EmailAuthProvider.credential(withEmail: email, link: password)
I had to write this:
let credential = EmailAuthProvider.credential(withEmail: email, password: password)
One small details and stoped my code from working

Related

iOS: Crash on transaction With realm SDK

Exception Type: EXC_BAD_ACCESS
Exception Subtype: KERN_INVALID_ADDRESS 0x00000003d74249bd
Release Type: User
Realm framework version: 10.5.1
Xcode version: 12.3
iOS/OSX version: 14.3
-->
Crash on transaction
Crashed: com.apple.root.background-qos
0 Realm 0x1058abfb8 realm::Allocator::translate_less_critical(realm::Allocator::RefTranslation*, unsigned long) const + 68
1 Realm 0x1057fce30 realm::Array::init_from_ref(unsigned long) + 192
2 Realm 0x105ca356c realm::_impl::GroupFriend::get_history_ref(realm::Allocator&, unsigned long) + 68
3 Realm 0x105c3ba60 bool realm::Transaction::internal_advance_read<(anonymous namespace)::TransactLogValidator>((anonymous namespace)::TransactLogValidator*, realm::VersionID, realm::_impl::History&, bool) + 176
4 Realm 0x105c36400 realm::_impl::transaction::begin(std::__1::shared_ptrrealm::Transaction const&, realm::BindingContext*, realm::_impl::NotifierPackage&) + 416
5 Realm 0x105c2b77c realm::_impl::RealmCoordinator::promote_to_write(realm::Realm&) + 268
6 Realm 0x105ca1570 realm::Realm::begin_transaction() + 404
7 Realm 0x10588ee24 -[RLMRealm beginWriteTransactionWithError:] + 24
8 Inventa 0x10510b0a0 $s7Inventa15RealmDataHelperC33saveDataAA0I0CG_tFyycfU_Tf2i_n + 52
9 Inventa 0x1050c2c98 $sIeg_IeyB_TR + 20
10 libdispatch.dylib 0x19941c24c _dispatch_call_block_and_release + 32
11 libdispatch.dylib 0x19941ddb0 _dispatch_client_callout + 20
12 libdispatch.dylib 0x19942ea68 _dispatch_root_queue_drain + 656
13 libdispatch.dylib 0x19942f120 _dispatch_worker_thread2 + 116
14 libsystem_pthread.dylib 0x1e52d97d8 _pthread_wqthread + 216
15 libsystem_pthread.dylib 0x1e52e076c start_wqthread + 8
func Inventa15RealmDataHelperC33saveData(notifications: [Notifications]) {
Inventa23.shared56.realmHelper.removeStaleDistinctNotifications654(notificationsofZone: "ezone")
var filtered:[Notifications] = []
for notif in notifications {
for stId in notif.st_ids {
notif.stId = stId
notif.notif_key = "\(notif.ntId)-\(notif.stId))"
filtered.append(notif)
}
}
let backgroundQueue = DispatchQueue.global(qos: .background)
backgroundQueue.async(execute: {
do{
let realm = try Realm()
realm.beginWrite()
realm.add(filtered, update: .all)
try realm.commitWrite()
}
catch{
print(error)
}
})
}
internal func removeStaleDistinctNotifications654(notificationsofZone: String) {
let notificationsInDB = realm?.objects(Notifications.self)
let onlyGeoNotifsInDB = notificationsInDB?.filter({$0.notification_identifier == notificationsofZone})
if let toBeDeletedGeoNotifs = onlyGeoNotifsInDB?.filter({$0.createdAtTimeStamp < Inventa.shared.insertedTimeStamp}) {
if toBeDeletedGeoNotifs.count > 0 {
do {
try realm?.write {
realm?.delete(toBeDeletedGeoNotifs)
}
} catch {
print(error)
}
}
}
}

Firebase Auth.auth().signIn(with: credential) crashed

I am trying to add Facebook login by using firebase authentication. After successfully getting the access token, my app gets crashed at
SocialMediaIntegration.sharedInstance().performLogin(viewController: self) { (granterdPermission, declinedPermission, accessToken) in
self.showHud()
let credential = FacebookAuthProvider.credential(withAccessToken:accessToken)
Auth.auth().signIn(with: credential, completion: { (user, error) in
self.dismissHud()
if !FireBaseAuthHandler.sharedInstance().checkIfErrorExists(error:error){
self.showHud()
SocialMediaIntegration.sharedInstance().getInformationFromAccessToken(token: accessToken, completionHandler: { (data) in
self.dismissHud()
guard let uid = user?.uid else{ return }
self.updateUserAtFirebaseWithUId(uid: uid)
})
}
})
}
I am getting the token successfully but signIn(with:credential) function of Firebase itself gets crashed. I am not getting further calls.
func performLogin(viewController:UIViewController,completionHandler: #escaping CompletionHandler){
let loginManager = FBSDKLoginManager()
loginManager.logIn(withReadPermissions: ["public_profile", "email"], from: viewController) { (loginResult, error) in
if let err = error{
print(error.debugDescription)
}else{
if (loginResult?.isCancelled)! == true{
debugPrint("User cancelled login.")
}else{
debugPrint("accessToken:\(String(describing: loginResult?.token.tokenString))")
completionHandler((loginResult?.grantedPermissions)!,(loginResult?.declinedPermissions)!,(loginResult?.token.tokenString)!)
}
}
}
}
crash report :
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryM gtm_httpArgumentsString]: unrecognized selector sent to instance 0x600000228a20'
*** First throw call stack:
(
0 CoreFoundation 0x0000000108e031ab __exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000107902f41 objc_exception_throw + 48
2 CoreFoundation 0x0000000108e83a34 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x0000000108d860a8 ___forwarding___ + 1432
4 CoreFoundation 0x0000000108d85a88 _CF_forwarding_prep_0 + 120
5 FocusGame IOS 0x0000000104c5aaf1 -[FIRVerifyAssertionRequest unencodedHTTPRequestBodyWithError:] + 423
6 FocusGame IOS 0x0000000104c54fe3 -[FIRAuthBackendRPCImplementation postWithRequest:response:callback:] + 132
7 FocusGame IOS 0x0000000104c53f7f -[FIRAuthBackendRPCImplementation verifyAssertion:callback:] + 193
8 FocusGame IOS 0x0000000104c52e7e +[FIRAuthBackend verifyAssertion:callback:] + 95
9 FocusGame IOS 0x0000000104c3ad6b -[FIRAuth internalSignInAndRetrieveDataWithCredential:isReauthentication:callback:] + 760
10 FocusGame IOS 0x0000000104c3a99c -[FIRAuth internalSignInWithCredential:callback:] + 135
11 FocusGame IOS 0x0000000104c3a6e3 __43-[FIRAuth signInWithCredential:completion:]_block_invoke + 70
12 libdispatch.dylib 0x000000010c9f23f7 _dispatch_call_block_and_release + 12
13 libdispatch.dylib 0x000000010c9f343c _dispatch_client_callout + 8
14 libdispatch.dylib 0x000000010c9fb95b _dispatch_queue_serial_drain + 1162
15 libdispatch.dylib 0x000000010c9fc2df _dispatch_queue_invoke + 336
16 libdispatch.dylib 0x000000010c9f807d _dispatch_queue_override_invoke + 733
17 libdispatch.dylib 0x000000010c9ff1f9 _dispatch_root_queue_drain + 772
18 libdispatch.dylib 0x000000010c9fee97 _dispatch_worker_thread3 + 132
19 libsystem_pthread.dylib 0x000000010ceb75a2 _pthread_wqthread + 1299
20 libsystem_pthread.dylib 0x000000010ceb707d start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Pods details with their versions are as follows:
FBSDKCoreKit (4.28.0)
FBSDKLoginKit (4.28.0)
FBSDKShareKit (4.28.0)
Firebase (4.6.0)
FirebaseAnalytics (4.0.5)
FirebaseAuth (4.3.2)
FirebaseCore (4.0.11)
FirebaseDatabase (4.1.1)
FirebaseFirestore (0.9.2)
FirebaseInstanceID (2.0.6)
GTMSessionFetcher (1.1.12)

My Alert popup crashes my app - iOS

I am doing a registration page for me iOS app. I know that my server side code is fine. When the user has successfully signed in the alert that it triggers crashes my app. If i remove the alert then my app is fine (I know this because
i use the console to print out 'success'). Please can someone advise on why my alert causes this crash?
.....
let task = session.dataTask(with: request) { (data, response, error) in
// When request is complete, run code below
if let jsonData = data{
do{
let jsonObject = try JSONSerialization.jsonObject(with: jsonData, options: [])
print("jsonObject: \(jsonObject)")
guard
let myArray = jsonObject as? [String:Any] else{
print("error-2")
return
}
if let status = myArray["status"] as? Int{
// Communication with server successful
if(status == 200){
// Registration successful
if let message = myArray["message"] as? String{
self.displayAlertMessage(msg: message)
}
}
}
}catch let error{
print("print error: \(error)")
}
}else if let requestError = error{
print("error detail: \(requestError)")
}else{
print("unexpected error")
}
}
task.resume()
My alert function
// General Alert message function
func displayAlertMessage(msg: String){
let alert = UIAlertController.init(title: "Alert", message: msg, preferredStyle: .alert)
let userAction = UIAlertAction.init(title: "OK", style: .destructive, handler: nil)
alert.addAction(userAction)
present(alert, animated: true, completion: nil)
}
CONSOLE:
[MobileAssetError:29] Unable to copy asset information from https://mesu.apple.com/assets/ for asset type com.apple.MobileAsset.TextInput.SpellChecker
url: https://www.myDomaincom/myFolder/myphpFile.php?userEmail=e#gm.com&firstname=Tim&lastname=t&userPassword=bab
jsonObject: {
email = "e#gm.com";
firstname = Tim;
lastname = t;
message = "Registration success";
status = 200;
userId = 32;
}
2017-04-29 12:33:57.042 lmyApp[60847:11563379] *** Assertion failure in -[UIKeyboardTaskQueue waitUntilAllTasksAreFinished], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3600.6.21/Keyboard/UIKeyboardTaskQueue.m:432
2017-04-29 12:33:57.057 myApp[60847:11563379] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIKeyboardTaskQueue waitUntilAllTasksAreFinished] may only be called from the main thread.'
*** First throw call stack:
(
0 CoreFoundation 0x0000000109891d4b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000106ba421e objc_exception_throw + 48
2 CoreFoundation 0x0000000109895e42 +[NSException raise:format:arguments:] + 98
3 Foundation 0x000000010673966d -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
4 UIKit 0x0000000107bc4b65 -[UIKeyboardTaskQueue waitUntilAllTasksAreFinished] + 165
5 UIKit 0x0000000107335441 -[UIKeyboardImpl setDelegate:force:] + 1404
6 UIKit 0x0000000107755dde -[UIPeripheralHost(UIKitInternal) _reloadInputViewsForResponder:] + 981
7 UIKit 0x000000010775f5f8 -[UIPeripheralHost(UIKitInternal) _preserveInputViewsWithId:animated:reset:] + 498
8 UIKit 0x0000000107227543 -[UIViewController _presentViewController:modalSourceViewController:presentationController:animationController:interactionController:completion:] + 1178
9 UIKit 0x000000010722928e -[UIViewController _presentViewController:withAnimationController:completion:] + 4971
10 UIKit 0x000000010722c26b -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 530
11 UIKit 0x000000010722bd51 -[UIViewController presentViewController:animated:completion:] + 179
12 lifesci-PubMed 0x00000001065b3fd2 _TFC14lifesci_PubMed22RegisterViewController19displayAlertMessagefT3msgSS_T_ + 834
13 lifesci-PubMed 0x00000001065b3378 _TFFC14lifesci_PubMed22RegisterViewController24submitRegistrationTappedFP_T_U_FTGSqV10Foundation4Data_GSqCSo11URLResponse_GSqPs5Error___T_ + 2088
14 lifesci-PubMed 0x00000001065b3bcb _TTRXFo_oGSqV10Foundation4Data_oGSqCSo11URLResponse_oGSqPs5Error____XFdCb_dGSqCSo6NSData_dGSqS1__dGSqCSo7NSError___ + 203
15 CFNetwork 0x0000000109cafccc __75-[__NSURLSessionLocal taskForClass:request:uploadFile:bodyData:completion:]_block_invoke + 19
16 CFNetwork 0x0000000109caf578 __49-[__NSCFLocalSessionTask _task_onqueue_didFinish]_block_invoke + 308
17 Foundation 0x00000001066a69ad __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 7
18 Foundation 0x00000001066a668f -[NSBlockOperation main] + 101
19 Foundation 0x00000001066a4d8c -[__NSOperationInternal _start:] + 672
20 Foundation 0x00000001066a0ccf __NSOQSchedule_f + 201
21 libdispatch.dylib 0x000000010a7f50cd _dispatch_client_callout + 8
22 libdispatch.dylib 0x000000010a7d2e17 _dispatch_queue_serial_drain + 236
23 libdispatch.dylib 0x000000010a7d3b4b _dispatch_queue_invoke + 1073
24 libdispatch.dylib 0x000000010a7d6385 _dispatch_root_queue_drain + 720
25 libdispatch.dylib 0x000000010a7d6059 _dispatch_worker_thread3 + 123
26 libsystem_pthread.dylib 0x000000010aba4712 _pthread_wqthread + 1299
27 libsystem_pthread.dylib 0x000000010aba41ed start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Read the error reason, it implies the solution:
... may only be called from the main thread
DispatchQueue.main.async {
self.displayAlertMessage(msg: message)
}
[UIKeyboardTaskQueue waitUntilAllTasksAreFinished] may only be called from the main thread.
Ans : thread that was not the main thread (from a callback in a network request). The solution is to dispatch your calls to present the view controllers to the main thread.present your alert in main thread,
DispatchQueue.main.async(execute: {() -> Void in
//Code that presents or dismisses a view controller here
self.present(alert, animated: true, completion: nil)
})
or else update your view in main thread in here
if let message = myArray["message"] as? String{
DispatchQueue.main.async(execute: {() -> Void in
//Code that presents or dismisses a view controller here
self.displayAlertMessage(msg: message)
})
}
First of all, you should display your alert message on main thread.
Also, it might be useful to capture a weak reference to your controller.
final class SomeController: UIViewController {
func sendRequest() {
let message = "your message"
DispatchQueue.main.async { [weak self] in
self?.displayAlertMessage(msg: message)
}
}
func displayAlertMessage(msg: String){
// present
}
}

JavaScriptCore crash

I am using JavaScriptCore with multiple threads on iOS 9.3. One JSContext is shared by all the threads. The app crashes sometimes. Does anybody knows what is going on ?
func callFunction(function:String, date:NSDate, dataConfiguration:CDTimePeriodConfiguration, viz:CDViz, didFinish:((response:[String:AnyObject]?, error:NSError?) -> Void)?){
guard let jsonString = self.jsonString(self.apiOptions(date, dataConfiguration: dataConfiguration, viz: viz)) else{
let error = Error.errorWithCode(.ParametersMissing, failureReason: "Cannot create Rocket APIOptions")
didFinish?(response: nil, error: error)
return
}
let randomCallBackFunctionName = "callBackFromJS\(Int64(NSDate().timeIntervalSince1970 * 1000))\(random() % 100000)"
let callBackClosure: #convention(block) (response: [String:AnyObject]?, error: String?) -> Void = {
[weak self]
(response: [String:AnyObject]?, error: String?) -> Void in
var errorMessage:String? = error
if error == "null"{
errorMessage = nil
}
dispatch_async(dispatch_get_main_queue()) {
if let response = response where errorMessage == nil{
didFinish?(response: response, error: nil)
}
else{
if errorMessage == nil && response == nil{
errorMessage = "No reponse from Rocket"
}
let error = Error.errorWithCode(.RocketError, failureReason: errorMessage ?? "Rocket failed for unknown reason")
didFinish?(response: response, error: error)
self?.context.setObject(nil, forKeyedSubscript: randomCallBackFunctionName)
}
}
}
context.setObject(unsafeBitCast(callBackClosure, AnyObject.self), forKeyedSubscript: randomCallBackFunctionName)
let js = "var options = \(jsonString) ; Rocket.\(function)(options).then(function(res) { \(randomCallBackFunctionName)(res, null); }).catch(function(err) { \(randomCallBackFunctionName)(null, err); })"
self.context.evaluateScript(js)
}
0 JavaScriptCore 0x000000018533f3d0 JSC::JSLock::lock(long) + 28
1 JavaScriptCore 0x00000001850453f4 JSC::JSLockHolder::JSLockHolder(JSC::VM&) + 48
2 WebCore 0x0000000185e079a0 WebCore::JSGlobalObjectCallback::call() + 64
3 WebCore 0x0000000185aa3dd8 std::__1::__function::__func<WebCore::Document::postTask(WebCore::ScriptExecutionContext::Task)::$_0, std::__1::allocator<WebCore::Document::postTask(WebCore::ScriptExecutionContext::Task)::$_0>, void ()>::operator()() + 116
4 JavaScriptCore 0x0000000184f35540 WTF::callFunctionObject(void*) + 28
5 JavaScriptCore 0x0000000184f354c0 WTF::dispatchFunctionsFromMainThread() + 240
6 Foundation 0x00000001826a7e20 __NSThreadPerformPerform + 336
7 CoreFoundation 0x0000000181c9cefc __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 20
8 CoreFoundation 0x0000000181c9c990 __CFRunLoopDoSources0 + 536
9 CoreFoundation 0x0000000181c9a690 __CFRunLoopRun + 720
10 CoreFoundation 0x0000000181bc9680 CFRunLoopRunSpecific + 380
11 WebCore 0x0000000185779998 RunWebThread(void*) + 452
12 libsystem_pthread.dylib 0x000000018194fb28 _pthread_body + 152
13 libsystem_pthread.dylib 0x000000018194fa8c _pthread_start + 152
14 libsystem_pthread.dylib 0x000000018194d028 thread_start + 0
Try to call every JSContext related method and functions in one thread:
Create dispatch_queue:
my_queue = dispatch_queue_create("com.example.subsystem.taskXYZ", NULL);
Call methods and functions:
...
// Sync call
dispatch_sync(my_queue) {
...
}
// Async call
dispatch_async(my_queue) {
....
}

How to programmatically go back to root view controller with a global function?

I have 3 main VC (MyAccount, Register, Login). Then I have a Swift file(Manager.swift) where I set up a class function where after the registering or logging in it would dismiss the VC.
Manager.swift
class Manager {
class func registerUser(vc: UIViewController?, user_email : String, user_password : String){
let myUrl = NSURL(string: hostURL + "userRegister.php")
let request = NSMutableURLRequest(URL:myUrl!)
request.HTTPMethod = "POST";
// Compose a query string
let postString = "user_email=\(user_email)&user_password=\(user_password)";
request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding);
let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {
data, response, error in
if error != nil
{
print("error=\(error)")
return
}
// You can print out response object
print("response = \(response)")
// Print out response body
let responseString = NSString(data: data!, encoding: NSUTF8StringEncoding)
print("responseString = \(responseString)")
//Let’s convert response sent from a server side script to a NSDictionary object:
let myJSON = try!NSJSONSerialization.JSONObjectWithData(data!, options: .MutableLeaves) as? NSDictionary
if let parseJSON = myJSON {
let status = parseJSON["status"] as? String
let msg = parseJSON["message"] as? String
print("Status: \(status)")
if(status != "Success")
{
UIAlert.displayAlert(vc, title: "Error", message: msg!, dismissTxt: "OK")
}
else{
defaults.setBool(true, forKey: "isLoggedIn")
//My Failed attempt to go back to Root :C
vc?.navigationController?.popToRootViewControllerAnimated(true)
}
}
}
task.resume()
}
}
RegisterVC
buttonPressed(sender: AnyObject) {
Manger.registerUser(self, user_email:username, user_password:password1234)
}
I used navigationController?.popToRootViewControllerAnimated in an attempt to back
It would work but sometimes the app would crash, spitting out this:
2015-10-02 14:51:01.410 Retail_Template[4551:261846] * Assertion failure in -[UIKeyboardTaskQueue waitUntilAllTasksAreFinished], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3505.16/Keyboard/UIKeyboardTaskQueue.m:378
2015-10-02 14:51:01.415 Retail_Template[4551:261846] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIKeyboardTaskQueue waitUntilAllTasksAreFinished] may only be called from the main thread.'
*** First throw call stack:
(
0 CoreFoundation 0x009f8a94 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x02b26e02 objc_exception_throw + 50
2 CoreFoundation 0x009f892a +[NSException raise:format:arguments:] + 138
3 Foundation 0x010bd3e6 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 118
4 UIKit 0x021f9d2e -[UIKeyboardTaskQueue waitUntilAllTasksAreFinished] + 180
5 UIKit 0x019e14f2 -[UIKeyboardImpl setDelegate:force:] + 703
6 UIKit 0x019e122e -[UIKeyboardImpl setDelegate:] + 60
7 UIKit 0x01ddd1d6 -[UIPeripheralHost(UIKitInternal) _reloadInputViewsForResponder:] + 1208
8 UIKit 0x01de6bef -[UIPeripheralHost(UIKitInternal) _preserveInputViewsWithId:animated:reset:] + 502
9 UIKit 0x01de6c85 -[UIPeripheralHost(UIKitInternal) _preserveInputViewsWithId:animated:] + 57
10 UIKit 0x0190dd0a -[UINavigationController navigationTransitionView:didStartTransition:] + 1029
11 UIKit 0x01903bf4 -[UINavigationController _startCustomTransition:] + 5104
12 UIKit 0x01913c0b -[UINavigationController _startDeferredTransitionIfNeeded:] + 801
13 UIKit 0x01914d05 -[UINavigationController __viewWillLayoutSubviews] + 68
14 UIKit 0x01aded9f -[UILayoutContainerView layoutSubviews] + 252
15 UIKit 0x017cb16b -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 813
16 libobjc.A.dylib 0x02b3b059 -[NSObject performSelector:withObject:] + 70
17 QuartzCore 0x003ed60c -[CALayer layoutSublayers] + 144
18 QuartzCore 0x003e128e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 388
19 QuartzCore 0x003e10f2 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
20 QuartzCore 0x003d3c2b _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 317
21 QuartzCore 0x00407c23 _ZN2CA11Transaction6commitEv + 589
22 QuartzCore 0x00407fbd _ZN2CA11Transaction14release_threadEPv + 289
23 libsystem_pthread.dylib 0x04bc32f7 _pthread_tsd_cleanup + 93
24 libsystem_pthread.dylib 0x04bc3051 _pthread_exit + 108
25 libsystem_pthread.dylib 0x04bc3734 pthread_get_stackaddr_np + 0
26 libsystem_pthread.dylib 0x04bc0e0e start_wqthread + 30
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Not sure what I'm doing wrong here.
Any solution will be appreciated. Thanks!
As your error says:
may only be called from the main thread.
Your operation should be called into main thread. As shown into below code:
dispatch_async(dispatch_get_main_queue()) {
//Perform your task here.
}

Resources