iOSで画面のオン/オフを確認するにはどうすればよいですか?私は画面が現在オンであるかどうか、私のアプリがバックグラウンドであるかどうかを知りたい。私はこれにイベントリスナーを持っていたいと思います。ありがとう。iOS:デバイス画面のオン/オフを検出できますか?
答えて
iosで画面の状態を取得するためにこのコードを試すことができます。
スウィフトあなたが行うことができます3でCFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), //center
NULL, // observer
displayStatusChanged, // callback
CFSTR("com.apple.iokit.hid.displayStatus"), // event name
NULL, // object
CFNotificationSuspensionBehaviorDeliverImmediately);
ごめんなさい、私はこのコード部分をよく理解していません。もっと説明しますか?私はこれに新しいです。私はこれを迅速に書きます。アドバイスはありますか? – user6539552
私は "CFSTR"とCFNotificationSuspensionBehaviorDeliverImmediatelyにエラーが発生したコードも試しました – user6539552
:
override func viewDidLoad() {
super.viewDidLoad()
// Observer UIApplicationDidBecomeActive,UIApplicationDidEnterBackground
NotificationCenter.default.addObserver(
self,
selector: #selector(MyViewController.applicationDidBecomeActive(notification:)),
name: NSNotification.Name.UIApplicationDidBecomeActive,
object: nil)
NotificationCenter.default.addObserver(
self,
selector: #selector(MyViewController.applicationDidEnterBackground(notification:)),
name:NSNotification.Name.UIApplicationDidEnterBackground,
object: nil)
}
func applicationDidBecomeActive(notification: NSNotification) {
// here my app did become active
}
func applicationDidEnterBackground(notification: NSNotification) {
// here my app did enter background
}
あなたはofficial guideで詳細を見つけることができます。実際のソースから
詳細:私は画面ロックを検出した場合/代わりにイベントのロックを解除何
extension NSNotification.Name {
// These notifications are sent out after the equivalent delegate message is called
@available(iOS 4.0, *)
public static let UIApplicationDidEnterBackground: NSNotification.Name
@available(iOS 4.0, *)
public static let UIApplicationWillEnterForeground: NSNotification.Name
public static let UIApplicationDidFinishLaunching: NSNotification.Name
public static let UIApplicationDidBecomeActive: NSNotification.Name
public static let UIApplicationWillResignActive: NSNotification.Name
public static let UIApplicationDidReceiveMemoryWarning: NSNotification.Name
public static let UIApplicationWillTerminate: NSNotification.Name
public static let UIApplicationSignificantTimeChange: NSNotification.Name
public static let UIApplicationWillChangeStatusBarOrientation: NSNotification.Name // userInfo contains NSNumber with new orientation
public static let UIApplicationDidChangeStatusBarOrientation: NSNotification.Name // userInfo contains NSNumber with old orientation
// userInfo dictionary key for status bar orientation
public static let UIApplicationWillChangeStatusBarFrame: NSNotification.Name // userInfo contains NSValue with new frame
public static let UIApplicationDidChangeStatusBarFrame: NSNotification.Name // userInfo contains NSValue with old frame
// userInfo dictionary key for status bar frame
@available(iOS 7.0, *)
public static let UIApplicationBackgroundRefreshStatusDidChange: NSNotification.Name
@available(iOS 4.0, *)
public static let UIApplicationProtectedDataWillBecomeUnavailable: NSNotification.Name
@available(iOS 4.0, *)
public static let UIApplicationProtectedDataDidBecomeAvailable: NSNotification.Name
// Key in options dict passed to application:[will | did]FinishLaunchingWithOptions and info for UIApplicationDidFinishLaunchingNotification
// This notification is posted after the user takes a screenshot (for example by pressing both the home and lock screen buttons)
@available(iOS 7.0, *)
public static let UIApplicationUserDidTakeScreenshot: NSNotification.Name
}
ありがとうございます。これは私のアプリの状態をチェックすることしかできないようだ。私がする必要があるのは、オンまたはオフになっている画面の状態を確認することです – user6539552
これに関するアドバイスはありますか? – user6539552
あなたが望むことをするためのパブリックAPIはありません:警告、あなたがいくつかのプライベートAPIを使用する場合、あなたのアプリはAppleのレビューでは有効ではないと判断される可能性があります。公式APIガイドラインを使用する必要があります –
- 1. 検出iOSデバイス
- 2. iOS Bluetooth APIでAndroidデバイスを検出できますか?
- 3. バックグラウンドでiOSの画面タッチを検出する
- 4. iOS 5.x - 画面に表示されたときの検出
- 5. iosデバイスのイオンブランク画面の問題
- 6. 画面でフラグメントを検出
- 7. ユーザーがiOSの画面キャプチャボタンを押しているかどうかを検出できますか?
- 8. iOS AirPlay画面のミラーリング機能を検出する
- 9. iOS 4キーボードがBluetoothと画面上にあるときをどのように検出できますか?
- 10. cocos2dの画面*のどこにでもタッチを検出できますか?
- 11. OnPause()の画面の向きの変化を検出します。
- 12. iOS Core Bluetooth - スキャンから実際のデバイスを検出できません。
- 13. iOSがQuickTime Playerを使用して画面の録画を検出/ブロックする
- 14. 画面のオン/オフ検出
- 15. 3次元でのiOSデバイスの動き検出
- 16. Mac OSXでWi-Fiを使用しているiOSデバイスやAndroidデバイスを検出または検出します。
- 17. iOSデバイスがHDビデオを再生できるかどうかを検出する
- 18. iOS Swiftによる外部画面の検出
- 19. iOS Beginner:画面の向き
- 20. 画面の向きios
- 21. IOS画面の向きphonegap
- 22. iOSデバイスの起動画面イメージまたはバックグラウンドイメージサイズが異なる
- 23. Samsung Galaxy S2は画面上の署名を検出できますか?
- 24. Android 2.2以降で画面の向きを検出する
- 25. JavaScriptで画面の向きを検出する
- 26. jQueryでラウンド画面を検出しますか?
- 27. iOS Bluetoothがデバイスを検出しない
- 28. バックグラウンドアプリケーションでのロック画面の検出
- 29. vb.netの画面キャプチャを検出する
- 30. XamarinのiOS /アンドロイド:私はフォームをxamarin使用してモバイルアプリに取り組んでいますロック画面/ホーム画面のクリック検出やスワイプ検出
?それをしてもいいですか? (スクリーンをオンにする代わりに) – user6539552