我的警报弹出窗口使我的应用程序崩溃 - iOS

蒂姆

我正在为我的 iOS 应用程序做一个注册页面。我知道我的服务器端代码很好。当用户成功登录它触发的警报时,我的应用程序崩溃了。如果我删除警报,那么我的应用程序就可以了(我知道这一点是因为我使用控制台打印出“成功”)。请有人告诉我为什么我的警报会导致这次崩溃?

 .....
 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()

我的提醒功能

 // 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)
}

安慰:

    [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/[email protected]&firstname=Tim&lastname=t&userPassword=bab
jsonObject: {
    email = "[email protected]";
    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) 
瓦迪安

阅读错误原因,它暗示了解决方案:

...只能从主线程调用

DispatchQueue.main.async {
    self.displayAlertMessage(msg: message)
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

我的iOS应用程序死机,但没有出现错误

来自分类Dev

iOS:在我的应用程序的xcode中设置默认语言

来自分类Dev

iOS 8.0 UIWebView文件输入使我的应用程序崩溃

来自分类Dev

iOS 7更新对我的应用程序的影响

来自分类Dev

我的ios应用程序使用加密吗?

来自分类Dev

iOS 7中的应用程序崩溃

来自分类Dev

无法删除我的ios应用程序(完全)

来自分类Dev

iOS 7何时关闭我的应用程序?

来自分类Dev

我的iOS 7应用程序需要iCloud开关吗?

来自分类Dev

为什么我的更新后的应用程序仅在IOS8上启动时崩溃?

来自分类Dev

在performBlock中重置我的NSManagedObjectContext时,iOS 8应用程序崩溃

来自分类Dev

如果我买不起Mac,如何开发iOS应用程序?

来自分类Dev

我的iOS应用程序有多少次安装?

来自分类Dev

在iOS上重置模拟器后,我第一次运行黄瓜应用程序崩溃

来自分类Dev

iOS将文件导入我的应用程序

来自分类Dev

我的ios应用程序使用加密吗?

来自分类Dev

上传我的iOS应用程序时出现错误

来自分类Dev

我的iPhone应用程序因ios 7而崩溃

来自分类Dev

iOS应用程序随机崩溃

来自分类Dev

iOS应用程序对某些用户崩溃

来自分类Dev

在iOS中设置全局变量后,我的应用程序崩溃了

来自分类Dev

在performBlock中重置我的NSManagedObjectContext时,iOS 8应用程序崩溃

来自分类Dev

从ios应用程序的弹出窗口获取popOver

来自分类Dev

当应用程序在ios中崩溃时,我们可以显示警报吗?

来自分类Dev

使用UnobservedTaskException停止HockeyApp使我的Xamarin iOS应用程序崩溃

来自分类Dev

当我在真实设备 iOS 中运行它时应用程序崩溃

来自分类Dev

当我恢复应用程序时 iOS 崩溃:“applicationDidBecomeActive:]: unrecognized selector sent to instance”

来自分类Dev

我的 iOS 应用程序仅在 iPhone 上崩溃,但在 iPad 上运行

来自分类Dev

当我单击打开弹出窗口的按钮时应用程序崩溃

Related 相关文章

  1. 1

    我的iOS应用程序死机,但没有出现错误

  2. 2

    iOS:在我的应用程序的xcode中设置默认语言

  3. 3

    iOS 8.0 UIWebView文件输入使我的应用程序崩溃

  4. 4

    iOS 7更新对我的应用程序的影响

  5. 5

    我的ios应用程序使用加密吗?

  6. 6

    iOS 7中的应用程序崩溃

  7. 7

    无法删除我的ios应用程序(完全)

  8. 8

    iOS 7何时关闭我的应用程序?

  9. 9

    我的iOS 7应用程序需要iCloud开关吗?

  10. 10

    为什么我的更新后的应用程序仅在IOS8上启动时崩溃?

  11. 11

    在performBlock中重置我的NSManagedObjectContext时,iOS 8应用程序崩溃

  12. 12

    如果我买不起Mac,如何开发iOS应用程序?

  13. 13

    我的iOS应用程序有多少次安装?

  14. 14

    在iOS上重置模拟器后,我第一次运行黄瓜应用程序崩溃

  15. 15

    iOS将文件导入我的应用程序

  16. 16

    我的ios应用程序使用加密吗?

  17. 17

    上传我的iOS应用程序时出现错误

  18. 18

    我的iPhone应用程序因ios 7而崩溃

  19. 19

    iOS应用程序随机崩溃

  20. 20

    iOS应用程序对某些用户崩溃

  21. 21

    在iOS中设置全局变量后,我的应用程序崩溃了

  22. 22

    在performBlock中重置我的NSManagedObjectContext时,iOS 8应用程序崩溃

  23. 23

    从ios应用程序的弹出窗口获取popOver

  24. 24

    当应用程序在ios中崩溃时,我们可以显示警报吗?

  25. 25

    使用UnobservedTaskException停止HockeyApp使我的Xamarin iOS应用程序崩溃

  26. 26

    当我在真实设备 iOS 中运行它时应用程序崩溃

  27. 27

    当我恢复应用程序时 iOS 崩溃:“applicationDidBecomeActive:]: unrecognized selector sent to instance”

  28. 28

    我的 iOS 应用程序仅在 iPhone 上崩溃,但在 iPad 上运行

  29. 29

    当我单击打开弹出窗口的按钮时应用程序崩溃

热门标签

归档