1

I have an ios app in Swift.The app runs fine and does not crash when uploaded locally from xcode. But the app is crashing when uploaded from testflight. I found that there is nothing wrong in code. I have implemented Crashlytics in my app, it has given following report.

Crashed: com.apple.main-thread
EXC_BREAKPOINT 0x0000000100160fe4

Crashed: com.apple.main-thread
0  App                     0x100160fe4 HomeViewController.viewDidLoad() -> () (HomeViewController.swift:57)

1  App                     0x100161014 @objc HomeViewController.viewDidLoad() -> () (HomeViewController.swift)

2  UIKit                          0x18c373ec0 -[UIViewController loadViewIfRequired] + 1036

3  UIKit                          0x18c38b94c -[UIViewController __viewWillAppear:] + 132

4  UIKit                          0x18c5101d4 -[UINavigationController _startCustomTransition:] + 1144

5  UIKit                          0x18c42ab78 -[UINavigationController _startDeferredTransitionIfNeeded:] + 676

6  UIKit                          0x18c42a7e0 -[UINavigationController __viewWillLayoutSubviews] + 64

7  UIKit                          0x18c42a744 -[UILayoutContainerView layoutSubviews] + 188

8  UIKit                          0x18c37107c -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1200

9  QuartzCore                     0x189561274 -[CALayer layoutSublayers] + 148

10 QuartzCore                     0x189555de8 CA::Layer::layout_if_needed(CA::Transaction*) + 292

11 QuartzCore                     0x189555ca8 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 32

12 QuartzCore                     0x1894d134c CA::Context::commit_transaction(CA::Transaction*) + 252

13 QuartzCore                     0x1894f83ac CA::Transaction::commit() + 504
14 QuartzCore                     0x1894f8e78 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 120

15 CoreFoundation                 0x1861f09a8 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32

16 CoreFoundation                 0x1861ee630 __CFRunLoopDoObservers + 372

17 CoreFoundation                 0x1861eea7c __CFRunLoopRun + 956

18 CoreFoundation                 0x18611eda4 CFRunLoopRunSpecific + 424

19 GraphicsServices               0x187b88074 GSEventRunModal + 100

20 UIKit                          0x18c3d9058 UIApplicationMain + 208

21 App                     0x1000d8688 main (NewProductData.swift:18)

22 libdyld.dylib                  0x18512d59c start + 4

I am not understanding anything from this reports, please help me out if anyone knows.

Here is viewDidload

  override func viewDidLoad() {
    super.viewDidLoad()
     Giving instance of HomeViewController to AppDelegate
      let appDele = UIApplication.shared.delegate as! AppDelegate
      appDele.homeVC = self
    token = FIRInstanceID.instanceID().token()!
//Method to handle Firebase token  
    UserDefaults.standard.set(token, forKey: "Notificationtoken")
    print("@@@@@@@@@@@@@@@@@@@@@@@ token provided is \(String(describing: token))")
     let tokenstr = UserDefaults.standard.value(forKey: "Notificationtoken") as! String
    if(token == tokenstr){
        handleFCMToken(token: tokenstr)
    }
    else{
        handleFCMToken(token: token!)

    }

    setUpNavBar()
    setPopUpImage()
    setUpcarousel()
    setUpDelegates()
    let help = Helper()

    help.setUpGoogleAnalytics(screenName: "Home")

    self.presenter = HomeViewPresenter(homeView: self)
    presenter.getCarousel()
    if(showProfile){
        ProfileClicked()
    }
    // Do any additional setup after loading the view.
}

And here is viewWillAppear

 override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    setUpUI()


}

and method of setupUI

 func setUpUI(){
    let wholesaler:Wholesaler = Helper.getWsProfile()

    DispatchQueue.main.async {
        self.wholesalerName.text = "Hello, \(wholesaler.wholesaler_name)"
        self.pdsPoints.text = "\(wholesaler.pdsPoints!)"
        self.visibilityPoints.text = "\(wholesaler.visibilityPoins!)"
    }
    iconNameString = ["SMS","Customer\n Groups","Visibility\n Contest","My\n Earnings","\(wholesaler.lastSchemeMonth!)\n Schemes","App\n News", "", "Contact\n Us"]

}
Prathamesh
  • 140
  • 1
  • 2
  • 15
  • You seems to have an issue on the `viewDidLoad()` of `HomeViewController`. What are your doing in `viewDidLoad()`? – Larme Jun 05 '17 at 13:13
  • Please, post line 57 of the `HomeViewController.swift` file. – Max Pevsner Jun 05 '17 at 13:17
  • This could mean there is something wrong for **updating** your app. Does it also crash on devices where it was never installed before? We had a similar issue before for the sqlite of our app. The solution was to tell our testers to delete the app. Then install it fresh. Idk if your case is similar but it could be – mfaani Jun 05 '17 at 18:00
  • @Larme,@Max Pevsner I am calling notification token token = FIRInstanceID.instanceID().token()! , this code is on li8ne 57 – Prathamesh Jun 06 '17 at 05:12
  • @Honey no only testflight build crashes on every device but if installed through Xcode locally it doesn't crash – Prathamesh Jun 06 '17 at 05:15
  • Could `FIRInstanceID.instanceID().token()!` be nil? And the `!` is then causing the crash? Try to run you app from XCode in Release Mode. – Larme Jun 06 '17 at 08:44
  • @Larme I already tried to run in release mode, but it is working fine no error, no crashes. – Prathamesh Jun 06 '17 at 09:36
  • Generally you should not force unwrapping. – emrcftci Jun 28 '19 at 12:15

1 Answers1

0

I think that viewing some code of your HomeViewController will give us more insight.

But here some comments:

  • Not sure about the full stack, but its seems weird that viewWillAppear is being called before viewDidLoad for some reason. Are you calling super correctly on those corresponding methods?
  • Have you try profiling the app using instruments in release mode vs debug mode? You can manage this on your schema settings.
  • Another hint, but I think it kind of advanced for your scenario, is the optimization level. Go to your target settings and search for Optimization Level, you'll notice it is different for debug and release. Sometimes complex algorithms with multiple blocks and/or threads may be affected by this.

Home it helps

Omer
  • 5,470
  • 8
  • 39
  • 64
  • Which line on `viewdidLoad` is 57? Looking at the code, it can be related to some unwrapping scenario: are you sure `...token()!` always returns a value? Check this out https://stackoverflow.com/a/40014002/219777 – Omer Jun 06 '17 at 15:18
  • ' token = FIRInstanceID.instanceID().token()! ' this line is on 57, it always returns value when run locally on Xcode. but for testflight I am not sure, Crashlytics reports are showing that it is crashing on line 57 – Prathamesh Jun 07 '17 at 05:05
  • Correct! ... so there must be a problem with the firebase setup somehow. Sorry, but I don't have much experience with the framework to provide a recommendation but I think its a good starting point! Cheers! – Omer Jun 07 '17 at 14:29
  • yes there was problem on that line it was returning nil, I wrote that code in app delegate and handle that nil error now it is working fine. – Prathamesh Jun 08 '17 at 07:00