iOS 后台退出app時不執行applicationWillTerminate的臨時解決方法


- (void)applicationDidEnterBackground:(UIApplication *)application {
    // 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.
    //實現一個可以后台運行幾分鍾的權限, 當用戶在后台強制退出程序時就會走applicationWillTerminate 了.
    [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:nil];
    
}

 

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    NSString * AddressBookIndex = @"AddressBook_index";
    NSString * AddressBookDataArray = @"AddressBook_dataArray";
    NSString * AddressBookPhonePerson = @"AddressBook_Person";
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:AddressBookIndex];
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:AddressBookDataArray];
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:AddressBookPhonePerson];
    
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2026 CODEPRJ.COM