调用performFetchWithCompletionHandler时,ViewController对象无效

时间:2016-03-07 03:29:38

标签: ios swift

我收到了测试人员的崩溃报告,其中我的MasterViewController创建的主用户对象(显然)为nil或无效,当操作系统调用performFetchWithCompletionHandler时。我知道当应用程序进入后台时,此对象已初始化,因为除非我处于要求User对象有效的特定状态,否则我不会请求后台提取通知。

以下是MasterViewController创建的片段:

class MasterViewController: UITableViewController {

static var services = [Service]()
static var user:User!
.
.
.

override func viewDidLoad() {
    super.viewDidLoad()

    // Create model objects
    MasterViewController.user = User()
   .
   .
   .

}

这是使用用户对象的提取调用:

func application(application: UIApplication, performFetchWithCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {

    print("Background notification: In performFetchWithCompletionHandler")

    if MasterViewController.user.getProviderState() == ProviderState.Offline ||
        !UserAPIManager.sharedInstance.isLoggedIn {

        print("Replied with .NoData")
        completionHandler (.NoData)

    } else {
       .
       .
       .
    }
}  

崩溃就行了:

if MasterViewController.user.getProviderState() == ProviderState.Offline ||
        !UserAPIManager.sharedInstance.isLoggedIn 

我得到的异常类型是 - 异常类型:SIGTRAP(此测试程序是在调试中构建的。)

在强制应用程序进入后台时,我从未在调试器中看到此错误。

另外,我没有在didReceiveMemoryWarning()中释放这个User对象。

感谢任何人的洞察力。

0 个答案:

没有答案
相关问题