Ios 在设备上运行应用程序时出现AppDelegate问题

Ios 在设备上运行应用程序时出现AppDelegate问题,ios,xcode,swift,appdelegate,Ios,Xcode,Swift,Appdelegate,我有一个应用程序,它有一个简单的计时器,在使用SpriteKit的动画viewcontroller上运行。我希望计时器继续运行,因此我使用通知中心并在AppDelegate中发布通知,如下所示: func applicationWillResignActive(application: UIApplication) { NSNotificationCenter.defaultCenter().postNotificationName("stopTimerNotification", obj

我有一个应用程序,它有一个简单的计时器,在使用SpriteKit的动画viewcontroller上运行。我希望计时器继续运行,因此我使用通知中心并在AppDelegate中发布通知,如下所示:

func applicationWillResignActive(application: UIApplication) {
   NSNotificationCenter.defaultCenter().postNotificationName("stopTimerNotification", object: nil)
}

func applicationDidEnterBackground(application: UIApplication) {
         NSNotificationCenter.defaultCenter().postNotificationName("stopTimerNotification", object: nil)    
}

func applicationWillEnterForeground(application: UIApplication) {
           NSNotificationCenter.defaultCenter().postNotificationName("startTimerNotification", object: nil)      
}

func applicationDidBecomeActive(application: UIApplication) {
   NSNotificationCenter.defaultCenter().postNotificationName("startTimerNotification", object: nil)


}
当连接到Xcode时,我的计时器在设备上运行正常,当睡眠时间应用程序在设备上运行且未连接到Xcode时,我的计时器在设备上运行正常。我已经找过了,但找不出这个。有什么建议吗

调用这两个通知时执行的代码为:

func stopTimerInBackground(note: NSNotification) {

    if(isRunningStopwatch == true) {

   stopPressed()

    stopTimerInBackgroundDate = NSDate()



    }

}

func startTimerInBackground(note: NSNotification) {


    var restartTimerInBackgroundDate:NSDate! = NSDate()

    if (isStopwatch == true) {

    previousElapsedTime = restartTimerInBackgroundDate.timeIntervalSinceDate(stopTimerInBackgroundDate)

    previousElapsedTime = 0

    startPressed()

    }

}

我只是想知道这是否是我必须更改的plist值?

对不起,我不理解您的问题,您能更具体地说明这个问题吗?无论如何,您的时间将收到两次StartTimer通知。使用这种方法,您只需使用您使用过的四种状态中的两种。感谢1月的提示。当我在iPhone上运行应用程序时,如果Azumio的睡眠时间应用程序正在运行,应用程序将正常运行。我只能认为睡眠时间应用程序可以在我的iPhone上运行我的应用程序正常运行计时器所需的服务。我不知道这些服务可能是什么。你能展示操作NSNotifications的代码吗?当然,Paul,我会编辑我的问题。