Thanks a lot! I’ve successfully integrated your codes to mine.
By the way, it looks like applicationDidEnterBackground and applicationWillEnterForeground are not called like common iOS app. They are called at odd timing.
Fortunately applicationDidBecomeActive and applicationWillResignActive are called right timing, so I’ll use them.