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.
Related
Whenever the current page changes by scrolling the pdf view in PDFkit, apps can detect the change adding the observer with PDFViewPageChanged.
The related sample code is as below,
// Add page change observer
NotificationCenter.default.addObserver(self,
selector: #selector(pageDidChange(notification:)),
name: Notification.Name.PDFViewPageChanged,
object: nil)
#objc private func pageDidChange(notification: Notification) {
// pdfView is of type PDFView
let currentPageNumber = pdfView.document?.index(for: pdfView.currentPage!)
}
From
How to know when user swipes to next page in PDFView of PDFKit?
PDFViewPageChanged works well in iOS 15.0 and before.
However, in case of iOS 15.2 and 15.4 (or later, latest)a function bound to PDFViewPageChanged is not called when the page changes.
I googled tons of pages to solve it. I couldn't find any solution or hints.
Please help me.
It's a very essential and fundamental function. So it's very strange.
Apple iOS PDFKit's PDFViewPageChanged notification was not delivered because a scrollview was added on the pdfview and the methods of the scrollview's delegate were overrode.
Before iOS 15.2, even though methods of the delegate were overrode, PDFKit's observer worked correctly.
However, since 15.2, in this case, the observer does not work well.
I removed the added scollview and added gesture recognizers instead to handle some events like tapping and panning.
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.
when my app is in foreground and receive push notification it displays notification on screen. After sometime (2-3 seconds) if user not tap the notification it goes, So my question is how can i handle push notification if user not tap on the notification. When the app is in foreground ios 10.0*
Just for example If user login at another device i will receive
notification on previously logged in device, if app is in foreground
the use will see the notification that login at another device, if
user tap on notification it moves to the login screen, but what if
user don't tap on notification
You could add a ViewController in your app that saved the push notification's data. And when the user navigates there, they can view them.
The duration of push notification is a system defaulted property. The default behavior is for that to show up for 2-3 seconds, and dismissed automatically if it's not tapped. You cannot change the duration of a push notification itself.
Previously, there is a trick that you can have a longer customized sound for your notification which can hold it on screen for up to 30 seconds, but that's from 5 years ago. I doubt that this can still be used today in iOS 10.0
I implemented push notifications into my app. The user gets a push notification from the server whenever there is a new message for him.
When the user clicks on the push notification, it opens the app. I want my app to reload a tableview when this happens, showing the user the recent newsfeed.
Is it possible in Swift 3?
As I understand, you are interesting in case of app that was opened on your recent newsfeed ViewController, then is closed to background by the user. Later on while receiving push, user clicks on it and opens the same newsfeed controller.
You have to subscribe to UIApplicationWillEnterForeground notification in your UIViewController like
NotificationCenter.default.addObserver(self, selector: #selector(yourMethod), name: NSNotification.Name.UIApplicationWillEnterForeground, object: nil)
and implement yourMethod like
func yourMethod() {
// send request to update newsfeed
// then update tableView
// tableView.reloadData()
}
Don't forget unsubscribe
deinit {
NotificationCenter.default.removeObserver(self)
}
It's the simplest solution and I described the simplest case. There are some more complicated cases I didn't describe, for example
The app is closed and you have to make hierarchy based on the push received in willFinishLaunchingWithOptions.
The app is opened on the other page, in this case you have to reconfigure viewControllers hierarchy to show required ViewController.
In this case you have to pass some data to required ViewController from the pressed Push Notification.
Hope it helps!
I'm working on an iOS project and would like to secure the app. I have been able to create and passcode view controller and it works fine but I want to present the passcode view whenever the app is about to enter the background or before it enters foreground. I know Appdelegate provides useful methods but how do I implement it to show the passcode view controller. I tried implementing the rootviewcontroller to present the passcode viewcontroller in the Appdelegate but it doesn't work and gives debugger message "attempt to present a viewcontroller that's not in the hierachy".
add this line to viewDidLoad() func:
NSNotificationCenter.defaultCenter().addObserver(self, selector: "showPasscodeView:", name: UIApplicationWillEnterForegroundNotification, object: nil)
Then present passcode view in showPasscodeView() func.