应用程序打开启动屏幕但崩溃(在 iOS 设备上)

Posted

技术标签:

【中文标题】应用程序打开启动屏幕但崩溃(在 iOS 设备上)【英文标题】:App opens launch screen but crashes (On iOS Device) 【发布时间】:2016-04-06 12:24:20 【问题描述】:

我在尝试在物理设备上测试我的应用时遇到了一些麻烦。每次我通过TestFlight 测试我的应用程序时,它只会打开LaunchScreen 片刻然后崩溃。这很奇怪,因为它在模拟器中完美运行。

我没有使用StoryBoards,我已经阅读过,人们说要删除info.plist 中的所有主要Storyboard 引用和构建设置。我已经这样做了,但它仍然无法正常工作。

我在下面附上了截图:

Info.plist

构建设置

另外,我觉得这可能与我的 AppDelegate 有关,因为我试图以编程方式完成所有事情。

AppDelegate.swift

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate 

    var window: UIWindow?

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool 
    
        // Override point for customization after application launch.
        self.window = UIWindow(frame:UIScreen.mainScreen().bounds)

        let navController = UINavigationController()
        let mainViewController = ViewController(nibName:nil, bundle:nil)

        // NavigationBar/Title colour
        navController.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.whiteColor()]
        UINavigationBar.appearance().barTintColor = UIColor(red:3/255, green:60/255, blue:115/255, alpha:1);


        // Push the viewcontroller onto the navigation controller
        navController.pushViewController(mainViewController, animated:false)

        self.window!.rootViewController = navController
        self.window?.makeKeyAndVisible()

        return true
    

    func applicationWillResignActive(application: UIApplication) 
    
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
    

    func applicationDidEnterBackground(application: UIApplication) 
    
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    

    func applicationWillEnterForeground(application: UIApplication) 
    
        // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
    

    func applicationDidBecomeActive(application: UIApplication) 
    
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    

    func applicationWillTerminate(application: UIApplication) 
    
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    

ViewController.swift - ViewDidLoad()

override func viewDidLoad() 
    
        super.viewDidLoad()

        self.title = "MyApp"
        self.view.backgroundColor = UIColor.whiteColor()
        self.navigationController!.navigationBar.barTintColor = UIColor(red: 0, green: 40/255, blue: 99/255, alpha: 1)
        self.navigationController!.navigationBar.tintColor = UIColor.whiteColor()


        // container
        mainContainer = UIView()

        // button
        btn_Schedule = UIButton()
        btn_Career = UIButton()
        btn_Social = UIButton()
        btn_Feedback = UIButton()
        btn_Details = UIButton()

        // Label
        lbl_Copywrite = UILabel()

        // Horizontal Dividing lines
        dividingLineTop = UIView()
        dividingLineBottom = UIView()

        // images
        img_Schedule = UIImage()
        img_Career = UIImage()
        img_Social = UIImage()
        img_Feedback = UIImage()
        img_Details = UIImage()

        img_Schedule = UIImage(named:"imgschedule.PNG")
        img_Career = UIImage(named:"imgcareer.PNG")
        img_Social = UIImage(named:"imgsocial.PNG")
        img_Feedback = UIImage(named:"contact.PNG")
        img_Details = UIImage(named:"imgdetails.PNG")

        // set up button clicks
        btn_Schedule.addTarget(self, action:"onMyScheduleButton_Clicked:", forControlEvents: UIControlEvents.TouchUpInside)
        btn_Career.addTarget(self, action:"onMyCareerButton_Clicked:", forControlEvents: UIControlEvents.TouchUpInside)
        btn_Social.addTarget(self, action:"onMySocialButton_Clicked:", forControlEvents: UIControlEvents.TouchUpInside)
        btn_Feedback.addTarget(self, action:"onFeedbackButton_Clicked:", forControlEvents: UIControlEvents.TouchUpInside)
        btn_Details.addTarget(self, action:"onMyDetailsButton_Clicked:", forControlEvents: UIControlEvents.TouchUpInside)

        if UIDevice.currentDevice().orientation.isLandscape.boolValue
        
            displayMenuInLandscapeMode()
        
        else 
        
            if(UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Pad)
            
                displayMenuInLandscapeMode()
            
            else
            
                displayMenuInPortraitMode()
            
        
    

如果有人可以提供帮助,那就太好了。

【问题讨论】:

您在将其发送到试飞之前在设备上运行过它吗?什么是崩溃日志消息和堆栈跟踪? 我没有物理 Mac,所以我使用的是 Macincloud。如果不使用 Testflight,我无法在设备上进行测试,而且我无法获得任何崩溃数据。除非您可以通过 XCode 访问它?我是 XCode 和 ios 开发的新手。 为什么不在您的设备上使用 Xcode 运行它?查看崩溃日志? 您可能需要添加一些崩溃日志记录代码/服务以获取更多详细信息。除非试飞会为您保留崩溃日志,否则不确定 因为我在我的 windows 机器上使用虚拟 mac 桌面,所以我无法将我的设备连接到那个虚拟 mac。 【参考方案1】:

我知道这很荒谬,但请删除 navController.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.whiteColor()]。 我遇到了同样的问题。一切都在本地工作,但不在 TestFlight 上。

你可以通过设置navigationBar.barStyle = UIBarStyle.black来改变标题的颜色

【讨论】:

以上是关于应用程序打开启动屏幕但崩溃(在 iOS 设备上)的主要内容,如果未能解决你的问题,请参考以下文章

启动屏幕后 React Native ios 崩溃

Adobe Air 应用程序在 iOS 上启动屏幕后自动崩溃

React-native:iOS 应用程序在具有命名空间 SPRINGBOARD 的设备上的启动屏幕中崩溃

Ionic 应用程序在启动屏幕 iOS 上崩溃

(iOS) iPad 应用程序在启动时随机崩溃

Xcode 6.3.2 应用程序在加载启动屏幕后崩溃