When using func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: #escaping (UNNotificationPresentationOptions) -> Void)
in AppDelegate, Sourcekitservice and swift spending
a lot of memory(40GB to 50Gb), RAM and CPU(over 90%) right after this method had been adding(no need to build or run) . Anyone has the same issue or can explain this for me.
I'm using Xcode 11.3.1 and macOS Mojave 10.14.6.
Thanks in advance.
Related
In willPresent Notification methods we receive payload when app in foreground state.
Actually I want to generate local notification from firebase push notification response and I couldn't understand which delegate methods is called when application in background and terminated state.
You should always invoke the willPresent method's completionHandler method as it is mentioned in the docs:
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: #escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.banner, .sound])
}
With this, you will be able to handle the notification even in backgrounded or terminated state.
Hello I am trying to display some notification datas.
In my notification I have a notification id to react deferently based on the pushed information.
I just cannot see what are those new UNNotificationPresentationOptions.
in my
userNotificationCenter(_: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: #escaping (UNNotificationPresentationOptions) -> Void)
I have
if notification.request.content.userInfo[keyName] as? String == "someId" {
// Bla bla stuffs
if #available(iOS 14.0, *) {
completionHandler([.list, .banner, .sound])
} else {
completionHandler([.alert])
}
} else if ...
But when using [.banner] or [.list] or [.banner, .list] (without .alert) I just got nothing in foreground. In an ideal world I'd love to have the notification listed in the Notification center and display relevant information in my app (before calling completion handler).
Am I using thoses options right ?
[.list] will only show the notification in the notification center (the menu that shows when you pull down from the top)
[.banner] will only pop down a banner from the top like a normal push notification
[.list, .banner] will do both: show the banner and also make sure it's on the list.
[.alert] does essentially the same as having [.list, .banner], from what I can tell. They just added these two options to give more granular control.
I just tested this locally and it did what I expected, so if it doesn't work for you it may not be hitting those lines. Did you add some breakpoints to verify that those lines were getting hit?
The notification shows in two ways
It shows in the top menu (the menu that shows when you pull down from the top)
In the notification center list
First, [.list] - It will show in the notification centre list, not in the top menu.
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: #escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.list, .badge, .sound])
}
Second [.banner] - It will show in the top menu but not in the list like list
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: #escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.banner, .badge, .sound])
}
If you want both things list and top menu in the Notification Center then do this
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: #escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.banner, .list, .badge, .sound])
}
It will give you both image output.
[.alert] does essentially the same as having [.list, .banner], from what I can tell. They just added these two options to give more granular control.
If you are looking for the code or tutorial then please check my video on Local Notification :- https://www.youtube.com/watch?v=yMbujKTf0uQ&t=1480s
I am opening webApplication in Mac app, to open webApplication I am using webView.load method to display content in webView. Most of the time able to load content but sometime throwing Authorization Failed error. It’s an intermittent issue.
func webView(_ webView: WKWebView, decidePolicyFor navigationResponse: WKNavigationResponse,
decisionHandler: #escaping (WKNavigationResponsePolicy) -> Void) {
if let response = navigationResponse.response as? HTTPURLResponse {
print("Response: \(response)")
if response.statusCode == 401 {
WebApplication using AppleConnect singleSignOn.
func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: #escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
if let serverTrust = challenge.protectionSpace.serverTrust {
completionHandler(URLSession.AuthChallengeDisposition.performDefaultHandling, URLCredential(trust: serverTrust))
//completionHandler(URLSession.AuthChallengeDisposition.performDefaultHandling, nil)
}
}
This error getting only in Big Sur OS, not in Catalina and It’s an intermittent issue not continuous. Anyone faced this issue before?
To resolve Authorization failed error, I have added non-persistent code
let webViewConfig = WKWebViewConfiguration()
webView = WKWebView(frame: view.frame, configuration: webViewConfig)
/** #abstract Returns a new non-persistent data store.
#discussion If a WKWebView is associated with a non-persistent data store, no data will
be written to the file system. This is useful for implementing "private browsing" in a web view.
*/
I have a custom delegate class called CertificatePinningDelegate which conforms to URLSessionDelegate. I'm using the delegate method
urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: #escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void)
to authenticate with the server. Now I want to write a unit test for this.
I've been trying to manually call the delegate method to pass a custom URLAuthenticationChallenge object, which seems impossible. Does anyone know any alternative/better option for this?
I have enabled UserNotifications in my app and it all works great, apart from a bug in the very beginning (First install). Local Notification requires to ask user for permission to send notifications and it comes as an alert on first install, where user chooses his/hers options ("Allow", "Don't Allow"). The problem is that this notification request is called in "applicationDidFinishLaunchingWithOptions" method in AppDelegate and it gets cut off by another alert, which is my LocalAuthorization(TouchID) alert initiated in viewDidLoad. Is there a way to put all those alerts in some kind of a queue, so they are fired one after another and not over each other? Or, to somehow tell viewDidLoad alert to wait for AppDelegate alert to finish showing? Any input is welcome. Thanks.
extension ViewController: UNUserNotificationCenterDelegate {
//for displaying notification when app is in foreground
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: #escaping (UNNotificationPresentationOptions) -> Void) {
//If you don't want to show notification when app is open, do something here else and make a return here.
//Even you you don't implement this delegate method, you will not see the notification on the specified controller. So, you have to implement this delegate and make sure the below line execute. i.e. completionHandler.
completionHandler([.alert, .badge, .sound])
}
// For handling tap and user actions
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: #escaping () -> Void) {
switch response.actionIdentifier {
case "action1":
print("Action First Tapped")//here you can your alert
case "action2":
print("Action Second Tapped")//here you can your alert
default:
break
}
completionHandler()
}
}
Move UNUserNotification authorization request from AppDelegate to viewDidLoad and call other alerts in completion block.