現在、swiftを勉強しております。始めたての初心者ですのでアドバイスをもらえると助かります。
アプリをバックグラウンドにする。→ 現在時刻を取得(タイムスタンプA)
アプリをフォアグラウンドにする。→ 現在時刻を取得(タイムスタンプB)
この時タイムスタンプA,Bの差が10分以上なら遷移。A,Bの時間を比較して差を出したいです。
このようになるコードを書きたいのですが、調べてみてもわかりません。
漠然とした質問で申し訳ございませんが、よろしくお願いいたします。
swift
1func applicationDidEnterBackground(_ application: UIApplication) { 2 // 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. 3 // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 4 5 } 6 func applicationWillEnterForeground(_ application: UIApplication) { 7 // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 8 9 }
タイミングは上記の間にコードの後ろに書き足せばいけると思いますが、そもそもの取得の方法が調べてもわかりません。
自分でも調べて出てきたコードはコピペして試してみましたが、コードが古いのかエラーなどが出てできませんでした。
わかりづらくてすいませんが、よろしくお願いいたします。
調べてみて「分かったこと」と「分からない」ことを具体的に書いて下さい。
回答1件
あなたの回答
tips
プレビュー