UIKeyboardWillChangeFrame Notification not called with emoji keyboard - ios

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

Related

viewDidLayoutSubviews & UIApplicationDidBecomeActive notification

In my viewDidLoad, I add code to follow UIApplication.didBecomeActive notification as follows:
NotificationCenter.default.addObserver(self,
selector: #selector(ViewController.applicationDidBecomeActive),
name: UIApplication.didBecomeActiveNotification,
object: UIApplication.shared)
The question is whether it is a given that once the notification is subscribed in viewDidLoad, the notification callback will not fire before viewDidLayoutSubviews() is called? It so happens on all my iOS devices across all iOS versions but it seems to be the source of bug if this is not true. Trying to figure out sources of all unreproducible bugs, not sure if this can be one of them.

How to prevent SpriteKit game from crashing when Notification Center is opened

I am having a weird issue with a SpriteKit game. The app crashes when a user opens Notification center or Control Center. I want the worldNode layer to be paused and the menuNode layer to be presented when the applicationWillResignActive is called, which is working fine when the home button is pressed. I've tried pausing my game from within the AppDelegate functions applicationWillResignActive and I've tried pausing when applicationDidBecomeActive is called if the game has started. I've tried using the NotificationCenter approach from within the ViewController both work when the Home Button/Home Gesture is used. How Should I handle this? Or is this just a bug in iOS 11?
I have this in the viewDidLoad method of my ViewController
NotificationCenter.default.addObserver(self, selector: #selector(appWillResignActive), name: NSNotification.Name.UIApplicationWillResignActive, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(appDidBecomeActive), name: NSNotification.Name.UIApplicationDidBecomeActive, object: nil)
Then each one of those selectors
It crashes on both if trying to present the menu when the appDidBecomeActive and appWillResignActive
#objc func appDidBecomeActive() {
print("appDidBecomeActive")
if GameScene.sharedInstance != nil {
print("presentingMenu")
GameScene.sharedInstance.presentMenuNode()
}
}
#objc func appWillResignActive() {
print("appWillResignActive")
if GameScene.sharedInstance != nil {
print("presentingMenu")
GameScene.sharedInstance.presentMenuNode()
}
}
I feel like I may be trying to approach this the wrong way, but what I don't understand is why does it work when the Home button/Home gesture is fired?
Edit:
After more testing I found that everything works as expected when running on iOS 10 devices. However when I run the DemoBots app that apple provides from their sample code it doesn't crash on iOS 11 and basically does what I want to do, so there has got to be a better way to handle the transitions of the game state, any input is appreciated.

Ios 10 iPhone 7 Keyboard disappears when receiving notification

I have a UITexField in a chat view controller.
When I'm editing my answer in the textfield, everything works fine execpt when I receive a push notification from my application.
This push notification is handled by my controller and a UIWindow is displayed on the top of the view controller. But the keyboard disappears .. only on my iPhone 7 and ios 10.
It works great on iPhone 6 and ios 9.3 for instance.
I guess it's related to ios 10 and UIWindow / UITextField, but I don't know what to do to fix that issue.
Do you have any idea ?
Thanks,
You can listen for when the application becomes active, either by implementing
func applicationDidBecomeActive(_: UIApplication)
in your appDelegate, or through notification center with
NotificationCenter.default.addObserver(self, selector: #selector(appBecameActive), name: Notification.Name.UIApplicationDidBecomeActive, object: nil)
When the user closes the notification window, you will receive this event, and then you can make the textfield active again with
textfield.becomeFirstResponder()
to bring back the keyboard.

How To Capture Image on volume hardware buttons?

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

NSNotificationCenter not working with Custom Keyboard

I am developing a custom keyboard using Swift. I want to get UIDeviceOrientationDidChangeNotification when Orientation changes; for that purpose, I am using:
NSNotificationCenter.defaultCenter().addObserver(self, selector: "changeOrientation:", name: UIDeviceOrientationDidChangeNotification, object: nil)
func changeOrientation(notification: NSNotification) { }
It works with a simple app, but doesn't work with custom keyboard extension.
To anyone new to Extensions
Select your extension target, Select 'play' it will ask you to chose an app to run. Select an appropriate app.
Then you are running with the debugger attached to your extension and can use breakpoints.
-Dan
What did you put in your changeOrientation function ?
Breakpoints aren't working for me in the keyboard swift file.

Resources