使用UIApplication.sharedApplication()。委托时的EXC_BREAKPOINT! AppDelegate中

时间:2016-05-24 08:00:24

标签: ios swift exception crash appdelegate

昨天Apple审核并接受了我们提交的应用版本。 除了我们已经解决的一些问题,还有一个崩溃报告让我发疯。

这是Fabric崩溃报告堆栈跟踪:

Crashed: com.apple.main-thread
0  xxxxxxxxxxxxxxxxx              0xb7444 ForecastCollectionViewController.(locationHelper(didReceiveUpdatedLocationWithObjectID : NSManagedObjectID, finishedLoading : Bool) -> ()).(closure #1) (ForecastCollectionViewController.swift:82)
1  xxxxxxxxxxxxxxxxx              0xb61d4 ForecastCollectionViewController.(locationHelper(didReceiveUpdatedLocationWithObjectID : NSManagedObjectID, finishedLoading : Bool) -> ()).(closure #1) (ForecastCollectionViewController.swift:1219)
2  libdispatch.dylib              0x23c27cbf _dispatch_call_block_and_release + 10
3  libdispatch.dylib              0x23c27cab _dispatch_client_callout + 22
4  libdispatch.dylib              0x23c2c559 _dispatch_main_queue_callback_4CF + 1532
5  CoreFoundation                 0x24057755 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
6  CoreFoundation                 0x24055c4f __CFRunLoopRun + 1590
7  CoreFoundation                 0x23fa41c9 CFRunLoopRunSpecific + 516
8  CoreFoundation                 0x23fa3fbd CFRunLoopRunInMode + 108
9  GraphicsServices               0x255c0af9 GSEventRunModal + 160
10 UIKit                          0x286dc435 UIApplicationMain + 144
11 xxxxxxxxxxxxxxxxx              0xd59c8 main (AppDelegate.swift:17)
12 libdispatch.dylib              0x23c50873 (Missing)

堆栈跟踪显示应用程序在第82行崩溃,看起来像这样:

    lazy var appDelegate = {() -> AppDelegate in
        return UIApplication.sharedApplication().delegate as! AppDelegate
    }()

它还说函数locationHelper(didReceiveUpdatedLocationWithObjectID:NSManagedObjectID,finishedLoading:Bool)是一个调用应用程序委托,然后导致应用程序崩溃。

func locationHelper(didReceiveUpdatedLocationWithObjectID locationID: NSManagedObjectID, finishedLoading: Bool) {
        dispatch_async(dispatch_get_main_queue()) {

            guard let location = self.appDelegate.managedObjectContext.objectWithID(locationID) as? LastVisited else {
                // Set updating status back to false
                self.updating = false
                // Stop refresh control animation
                self.stopRefreshControlAnimation(withSuccess: false) {
                    // Custom error
                    let errorDescription = NSLocalizedString("error", comment: "Show general error")

                    let errorMessage = Murmur(title: errorDescription, backgroundColor: Colors.sharedInstance.error, titleColor: .whiteColor(), font: UIFont.systemFontOfSize(13))
                    Whistle(errorMessage, action: .Present)
                }
                return
            }

            // Changes only made if is first loading action
            if self.isInitial {
                // Set tab bar active
                self.tabBarEnabled(active: true)
                // Set initial to false
                self.isInitial = false
            }

            // Append received location to current location variable
            self.currentLocation = location
            // Set search bar title
            var stringInSearchBar = "\(location.city)"
            if location.iso != "-" {
                stringInSearchBar = "\(stringInSearchBar), \(location.iso)"
            }
            var args = [String:AnyObject]()
            args[NSForegroundColorAttributeName] = UIColor.whiteColor()
            self.searchBar.setAttributedPlaceholder(stringInSearchBar, withAttributes: args)

            // Data changes
            if let data = location.offlineData {

                // Set new background if it has changed
                self.setBackgroundImage(withName: data.background!)
                // Set new background global variable
                GlobalSettings.sharedInstance.background = data.background!
                // Set new color model
                self.setColorModel(withPictocode: data.pictocode, daylight: data.daylight)
                print(data.pictocode)
                // Set last updated label
                self.dateFormatter.dateStyle = .ShortStyle
                self.dateFormatter.timeStyle = .ShortStyle
                self.dateFormatter.timeZone = nil
                self.refreshControlView.lastUpdatedLabel.text = self.dateFormatter.stringFromDate(data.timestamp!)

                // Remove tab bar items if not available
                if let meta = data.meta {

                    // Check if tab bar controller has been passed in objects dic
                    if let tabBarController = self.tabBarController, let currentControllers = tabBarController.viewControllers {
                        // Assign view controller array to local variable on initial start

                        var animated = true

                        var newViewControllers = [UIViewController]()
                        // Assign view controller array to local variable on initial start

                        let where2go = Where2GoViewController()
                        let wind = WindViewController()

                        newViewControllers.append(currentControllers[0])
                        newViewControllers.append(wind)
                        newViewControllers.append(where2go)

                        guard let satellite = meta.satelliteDomain, let radar = meta.radarDomain else {
                            // If not able to bind sat/rad values set standard views anyway
                            tabBarController.setViewControllers(newViewControllers, animated: true)
                            return
                        }

                        if satellite != "" {
                            let vc = SatelliteViewController()
                            newViewControllers.insert(vc, atIndex: 2)
                        }
                        if radar != "" {
                            let vc = RadarViewController()
                            if newViewControllers.count >= 4 {
                                newViewControllers.insert(vc, atIndex: 3)
                            } else {
                                newViewControllers.insert(vc, atIndex: 2)
                            }
                        }

                        if currentControllers.count == newViewControllers.count {
                            animated = false
                        }

                        tabBarController.setViewControllers(newViewControllers, animated: animated)
                    }
                }
            }

            // Reload collection view
            if self.collectionView!.dragging || self.collectionView!.decelerating {
                self.deferredReloading = true
            } else {
                self.collectionView?.reloadData()
            }

            // Stop reload
            if finishedLoading {
                self.stopRefreshControlAnimation(withSuccess: true, completionHandler: nil)
            }

            // Set updating status back to false
            self.updating = false

            // Set location helper to nil
            self.locationHelper = nil

            // Save core data
            self.appDelegate.saveContext()
        }
    }

我的两个猜测是:

  1. locationHelper中的objectWithID(didReceiveUpdatedLocationWithObjectID locationID:NSManagedObjectID,finishedLoading:Bool)导致导致崩溃的异常

  2. 线程

  3. 有谁知道问题可能是什么?

0 个答案:

没有答案