仅在临时构建中崩溃

时间:2018-04-14 13:51:47

标签: ios xcode swift4

我已经在应用程序上工作了几个星期,我在开发时已经在iOS模拟器上进行了测试,本周我作为开发人员注册并在实际设备上进行了测试。当我直接从XCode测试它时(连接电缆一切都很完美......没有奇怪的行为。但是当我测试它作为AD HOC .ipa文件时,当我按下应该向服务器发送JSON的按钮时它崩溃了。但我不知道为什么或如何......

我设法从我的设备上获取了一个日志文件,但我真的不明白。我希望有人可以帮助我朝着正确的方向前进。

Incident Identifier: 3C460EDB-06FE-49C3-BA24-01178AF6F047
CrashReporter Key:   58fc0aebb5f3205ced3a28c4ba3b8494a3bce3ad
Hardware Model:      iPhone8,1
Process:             LMRA First [301]
Path:                /private/var/containers/Bundle/Application/2C3462F1-F8B1-4BDD-BFED-EF42C91F4A47/LMRA First.app/LMRA First
Identifier:          be.stack51.LMRA-First
Version:             1 (1.0)
Code Type:           ARM-64 (Native)
Role:                Foreground
Parent Process:      launchd [1]
Coalition:           be.stack51.LMRA-First [453]


Date/Time:           2018-04-14 15:29:54.3285 +0200
Launch Time:         2018-04-14 15:29:38.7474 +0200
OS Version:          iPhone OS 11.2.6 (15D100)
Baseband Version:    4.30.02
Report Version:      104

Exception Type:  EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x0000000104184ecc
Termination Signal: Trace/BPT trap: 5
Termination Reason: Namespace SIGNAL, Code 0x5
Terminating Process: exc handler [0]
Triggered by Thread:  0

Filtered syslog:
None found

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   LMRA First                      0x0000000104184ecc specialized BaseLMRAViewController.launcSendDataTask(jsonData:dataType:) + 151244 (BaseLMRAViewController.swift:229)
1   LMRA First                      0x0000000104185b20 specialized BaseLMRAViewController.sendDataOverNetwork(dataType:) + 154400 (BaseLMRAViewController.swift:0)
2   LMRA First                      0x00000001041826fc closure #1 in closure #1 in BaseLMRAViewController.displayRemarksInput() + 141052 (BaseLMRAViewController.swift:0)
3   LMRA First                      0x000000010416c82c thunk for @callee_owned () -> () + 51244 (BaseController.swift:0)
4   libdispatch.dylib               0x00000001858a6a14 _dispatch_client_callout + 16
5   libdispatch.dylib               0x00000001858aef08 _dispatch_continuation_pop$VARIANT$mp + 428
6   libdispatch.dylib               0x00000001858b8848 _dispatch_source_invoke$VARIANT$mp + 1588
7   libdispatch.dylib               0x00000001858b3570 _dispatch_main_queue_callback_4CF$VARIANT$mp + 720
8   CoreFoundation                  0x0000000185ecf344 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
9   CoreFoundation                  0x0000000185eccf20 __CFRunLoopRun + 2012
10  CoreFoundation                  0x0000000185decc58 CFRunLoopRunSpecific + 436
11  GraphicsServices                0x0000000187c98f84 GSEventRunModal + 100
12  UIKit                           0x000000018f5455c4 UIApplicationMain + 236
13  LMRA First                      0x00000001041652fc main + 21244 (AppDelegate.swift:13)
14  libdyld.dylib                   0x000000018590c56c start + 4

Thread 1:
0   libsystem_kernel.dylib          0x0000000185a3cd80 __workq_kernreturn + 8
1   libsystem_pthread.dylib         0x0000000185b4f080 _pthread_wqthread + 1288
2   libsystem_pthread.dylib         0x0000000185b4eb6c start_wqthread + 4

Thread 2 name:  com.apple.uikit.eventfetch-thread
Thread 2:
0   libsystem_kernel.dylib          0x0000000185a1b568 mach_msg_trap + 8
1   libsystem_kernel.dylib          0x0000000185a1b3e0 mach_msg + 72
2   CoreFoundation                  0x0000000185ecf108 __CFRunLoopServiceMachPort + 196
3   CoreFoundation                  0x0000000185ecccd4 __CFRunLoopRun + 1424
4   CoreFoundation                  0x0000000185decc58 CFRunLoopRunSpecific + 436
5   Foundation                      0x0000000186821594 -[NSRunLoop+ 50580 (NSRunLoop) runMode:beforeDate:] + 304
6   Foundation                      0x00000001868409ac -[NSRunLoop+ 178604 (NSRunLoop) runUntilDate:] + 96
7   UIKit                           0x00000001900af7a8 -[UIEventFetcher threadMain] + 136
8   Foundation                      0x00000001869230f4 __NSThread__start__ + 996
9   libsystem_pthread.dylib         0x0000000185b502b4 _pthread_body + 308
10  libsystem_pthread.dylib         0x0000000185b50180 _pthread_body + 0
11  libsystem_pthread.dylib         0x0000000185b4eb74 thread_start + 4

Thread 3:
0   libsystem_kernel.dylib          0x0000000185a3c0f0 __psynch_cvwait + 8
1   libsystem_pthread.dylib         0x0000000185b52ce4 _pthread_cond_wait$VARIANT$mp + 640
2   libc++.1.dylib                  0x00000001850f3ea4 std::__1::condition_variable::wait+ 32420 (std::__1::unique_lock<std::__1::mutex>&) + 24
3   JavaScriptCore                  0x000000018d294f2c void std::__1::condition_variable_any::wait<std::__1::unique_lock<bmalloc::Mutex> >+ 10133292 (std::__1::unique_lock<bmalloc::Mutex>&) + 96
4   JavaScriptCore                  0x000000018d294e54 bmalloc::AsyncTask<bmalloc::Heap, void (bmalloc::Heap::*)()>::threadRunLoop+ 10133076 () + 172
5   JavaScriptCore                  0x000000018d2951b8 void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (*)(bmalloc::AsyncTask<bmalloc::Heap, void (bmalloc::Heap::*)()>*), bmalloc::AsyncTask<bmalloc::Heap, void (bmalloc::Heap::*)()>*> >+ 10133944 (void*) + 44
6   libsystem_pthread.dylib         0x0000000185b502b4 _pthread_body + 308
7   libsystem_pthread.dylib         0x0000000185b50180 _pthread_body + 0
8   libsystem_pthread.dylib         0x0000000185b4eb74 thread_start + 4

Thread 4 name:  WebThread
Thread 4:
0   libsystem_kernel.dylib          0x0000000185a1b568 mach_msg_trap + 8
1   libsystem_kernel.dylib          0x0000000185a1b3e0 mach_msg + 72
2   CoreFoundation                  0x0000000185ecf108 __CFRunLoopServiceMachPort + 196
3   CoreFoundation                  0x0000000185ecccd4 __CFRunLoopRun + 1424
4   CoreFoundation                  0x0000000185decc58 CFRunLoopRunSpecific + 436
5   WebCore                         0x000000018dd6184c RunWebThread+ 268364 (void*) + 560
6   libsystem_pthread.dylib         0x0000000185b502b4 _pthread_body + 308
7   libsystem_pthread.dylib         0x0000000185b50180 _pthread_body + 0
8   libsystem_pthread.dylib         0x0000000185b4eb74 thread_start + 4

Thread 5:
0   libsystem_pthread.dylib         0x0000000185b4eb68 start_wqthread + 0

Thread 6:
0   libsystem_pthread.dylib         0x0000000185b4eb68 start_wqthread + 0

Thread 7:
0   libsystem_pthread.dylib         0x0000000185b4eb68 start_wqthread + 0

Thread 0 crashed with ARM Thread State (64-bit):
    x0: 0x00000001043c0900   x1: 0x00000001c4242370   x2: 0x0000000000000008   x3: 0x0000000185a83318
    x4: 0x0000000000000006   x5: 0x0000000000000000   x6: 0x0000000000000064   x7: 0x00000000000002f0
    x8: 0x00000001c40552a0   x9: 0x0000000000000000  x10: 0x0000000000000002  x11: 0xbaddc0dedeadbead
   x12: 0x0000000000000065  x13: 0x0000000000000002  x14: 0x0000000000000000  x15: 0x000000000000ae72
   x16: 0x0000000185b4a8cc  x17: 0x000000010483e09c  x18: 0xfffffff01569925c  x19: 0x0000000000000000
   x20: 0x00000001c0021fe0  x21: 0x000000011a880000  x22: 0x0000000000000006  x23: 0x000000010418d1d0
   x24: 0x00000000000001c9  x25: 0x0000000000000000  x26: 0x00000001c42a2760  x27: 0x0000000000000000
   x28: 0x00000001c4242370   fp: 0x000000016bc9e970   lr: 0x0000000104184b7c
    sp: 0x000000016bc9e8b0   pc: 0x0000000104184ecc cpsr: 0x60000000

我认为错误,如果我正确读取它可能位于第229行......但不确定

//MARK: SENDDATA PROTOCOL IMPLEMENTATION:
    func launcSendDataTask(jsonData: Data, dataType: String) {

        var url: URL;

        switch dataType {
            case BaseConstants.DTMultiple:
                //TODO GET BUILD VALUE
                url = URL(string: AppDelegate.shared().base_urls.object(forKey: "multipleEntriesUrl") as! String)!;
                break;
            case BaseConstants.DTSingle:
#LINE 229 IS HERE:
                url = URL(string: AppDelegate.shared().base_urls.object(forKey: "singleEntryUrl") as! String)!;
                break;
            default:
                //TODO
                url = URL(string: AppDelegate.shared().base_urls.object(forKey: "singleEntryUrl") as! String)!;
                break;
        }



        // Specify this request as being a POST method
        var request = URLRequest(url: url);
        request.httpMethod = "POST"
        // Make sure that we include headers specifying that our request's HTTP body
        // will be JSON encoded
        var headers = request.allHTTPHeaderFields ?? [:]
        headers["Content-Type"] = "application/json"
        request.allHTTPHeaderFields = headers

        // Now let's encode out Post struct into JSON data...
        // ... and set our request's HTTP body
        request.httpBody = jsonData


        // Create and run a URLSession data task with our JSON encoded POST request
        let config = URLSessionConfiguration.default
        let session = URLSession(configuration: config)
        let task = session.dataTask(with: request) { (responseData, response, responseError) in
            guard responseError == nil else {
                NSLog("ERROR WITH CONNECTION ?");
                //completion?(responseError!)
                return
            }

            // APIs usually respond with the data you just sent in your POST request
            if let data = responseData/*01, let utf8Representation = String(data: data, encoding: .utf8) */{
                self.onSendDataTaskComplete(result: data, dataType: dataType);
            } else {
                print("no readable data received in response")
            }
        }
        task.resume()
    }

这是存储基本网址的plist文件。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>app_colors</key>
    <dict>
        <key>colorPrimary</key>
        <string>#06567b</string>
        <key>colorPrimaryDark</key>
        <string>#303F9F</string>
        <key>colorAccent</key>
        <string>#FF4081</string>
    </dict>
    <key>usesCapSettings</key>
    <true/>
    <key>base_urls</key>
    <dict>
        <key>singleEntryUrl</key>
        <string>https://xxxxx.xxxxx/post/x1</string>
        <key>multipleEntriesUrl</key>
        <string>https://xxxxx.xxxxx/post/x2</string>
    </dict>
</dict>
</plist>

(域名因安全问题而被修改)

我不明白为什么它可以在iOS模拟器上运行,也可以直接通过设备上的XCode运行,但不能在构建为AD HOC时运行...

有谁知道我做错了什么?

1 个答案:

答案 0 :(得分:0)

由强制转换引起的 - as! - 在失败时导致运行时陷阱。显然AppDelegate.shared().base_urls.object(forKey: "singleEntryUrl")没有返回String值,因此将其强制转换为此类会导致崩溃。修改代码以避免强制转换

guard let string = AppDelegate.shared().base_urls.object(forKey: "singleEntryUrl") as? String else { return }
guard let url = URL(string: string) else { return }