How To Capture Image on volume hardware buttons? - ios

I use this notification to catch pressing on volume hardware buttons:
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("volumeChanged:"), name: "AVSystemController_SystemVolumeDidChangeNotification", object: nil)
Notification is catch but volume indicator is shown in middle of the screen.Before iOS 9.2 was blocked by the notification, now is showing again. Is there any way to block that again
Thanks

Related

How to detect when the user takes a screenshot out of the application?

How to detect when the user takes a screenshot out of the application or application is not in active stage? I want to fire a push notification when user take screen shot out of the app or anywhere from iphone.
like this app :- https://apps.apple.com/us/app/liketoknow-it/id1154027990
Screenshot is a springboard event. This is not possible unless the application is active or in a jailbreak environment
I am not sure, what is the need of screenshot when app is not running as it will be screen shot of your device home screen, not the application. So it is not possible.
This is the solution when your app is running.
Here, UIApplicationUserDidTakeScreenshot will comes into the picture, screenshotTaken will be called for below case. Yes you have to create screenshotTaken method on your controller.
NotificationCenter.default.addObserver(self, selector: #selector(screenshotTaken), name: UIApplication.userDidTakeScreenshotNotification, object: nil)
You can try below option too
NotificationCenter.default.addObserver(forName: UIApplication.userDidTakeScreenshotNotification, object: nil, queue: OperationQueue.main) { notification in
print("Screenshot taken!")
}
Using this code detects screenshots.
NotificationCenter.default.addObserver(forName: .UIApplicationUserDidTakeScreenshot,
object: nil,
queue: OperationQueue.main) { notification in
print("\(notification) that a screenshot was taken!")
}

Block screen recoding but allow HDMI screen mirroring Swift 4

I need to stop Screen recoding, however I need to allow video sharing through HDMI.
I know the captured notification is usually used for this, but I cant find a way to separate out these two things.
UIScreen.main.addObserver(self, forKeyPath: "captured", options: .new, context: nil)
The above triggers notifications when screen recording is started / stopped. But also triggers when an external display is connected / disconnected (though I'm finding it to be intermittent here).
I have tried using the following to detect if a screen within the UIScreen is mirrored or just to check the screen count. Recordings show only one screen in the count, and mirrored screens should show a count of 2
recordingLabel.text = "count \(UIScreen.screens.count)"
for screen in UIScreen.screens {
if screen.mirrored != nil {
recordingLabel.text = "Mirrored - count \(UIScreen.screens.count)"
}
}
But again this is intermittent. Most of the time the count does not change on connecting a HDMI screen, but does change to 2 on disconnecting.
I have also found using UIScreen notifications work for connected / disconnected. But there seems to be a race condition happening with the captured notification that I still need to handle recordings.
NotificationCenter.default.addObserver(self, selector: #selector(connected), name: UIScreen.didConnectNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(disconnected), name: UIScreen.didDisconnectNotification, object: nil)
Is there any way to detect the type of recording or prevent the race from happening when both types of notifications trigger?
EDIT :
I have since found
NotificationCenter.default.addObserver(self, selector: #selector(captureChanged(notification:)), name: UIScreen.capturedDidChangeNotification, object: nil)
Which works better with the connection notifications, but it still triggers before I get a connected notification. I don't really want to add a timer to detect if the didConnect notification triggers after the captureChange, but that might be the only way

detect banner pop up from any other app

In iOS, is there a listening function that will enable an app detect when there is a banner (from any other application like whatsapp/snapchat/iMessage banners) on the screen/UI?
For example, to detect brightness change I have something like this:
NotificationCenter.default.addObserver(
self,
selector: #selector(self.levelChanged),
name: .UIScreenBrightnessDidChange,
object: nil)
I also found this post, which is similar but I want my app to just know (on a binary level) if there is a banner or not, I do not need to know the content or source app of the banner.

UIKeyboardWillChangeFrame Notification not called with emoji keyboard

First I had a UIViewController listenning for the UIKeyboardWillShow notification to adjust the screen for the keyboard. But every time I changed to emoji keyboard, the notification wasn't called.
So, I changed to UIKeyboardWillChangeFrame notification like this
NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardChanged(notification:)), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
It seems to work fine if I just change to emoji by tapping keyboard type.
However, if I press and hold keyboard type to select (my keyboard have more than one language) and select the emoji keyboard, the notification is not fired.
Anyone had something like this before? Any suggestions?
This is a bug in iOS 11, but there is a hacky temporary solution:
You can listen language mode changes:
NotificationCenter.default.addObserver(self, selector: #selector(inputModeDidChange(_:)), name: .UITextInputCurrentInputModeDidChange, object: nil)
And check for emoji:
if([[UITextInputMode currentInputMode].primaryLanguage isEqualToString:#"emoji"]) // layout again

How do I perform some code after app was connected to the internet and is in the background mode?

In didFinishLaunchingWithOptions I do:
AFNetworkReachabilityManager.shared().startMonitoring()
NotificationCenter.default.addObserver(self, selector: #selector(networkDidChangeStatus), name: NSNotification.Name.AFNetworkingReachabilityDidChange, object: nil)
my function for selector is following:
func networkDidChangeStatus() {
//UPLOAD CHANGES TO ICLOUD DATABASE
}
All I need to do is to upload changes immediately after device is connected to the network even when the app is not opened.
It works pretty well when app is in foreground mode, but do not know what to do when app is in the background mode. Is it possible at all?
I did turn on BACKGROUND MODES in Capabilities tab.

Resources