Notifications Landing Page

Okay, got that fixed… no errors but still not working. I added a ‘print’ in a few places within the notification so I can see when it progresses. Now I’m getting errors in my consul that look like this:

Notification
2021-11-20 20:03:47.945846-0600 KBA[13512:4157064] [connection] nw_endpoint_handler_set_adaptive_read_handler [C13.3 142.250.190.74:443 ready channel-flow (satisfied (Path is satisfied), viable, interface: en0, ipv4, ipv6, dns)] unregister notification for read_timeout failed
2021-11-20 20:03:47.945958-0600 KBA[13512:4157064] [connection] nw_endpoint_handler_set_adaptive_write_handler [C13.3 142.250.190.74:443 ready channel-flow (satisfied (Path is satisfied), viable, interface: en0, ipv4, ipv6, dns)] unregister notification for write_timeout failed
2021-11-20 20:03:50.608062-0600 KBA[13512:4156342] [connection] nw_endpoint_handler_set_adaptive_read_handler [C14.2 142.250.191.174:443 ready channel-flow (satisfied (Path is satisfied), viable, interface: en0, ipv4, ipv6, dns)] unregister notification for read_timeout failed
2021-11-20 20:03:50.608184-0600 KBA[13512:4156342] [connection] nw_endpoint_handler_set_adaptive_write_handler [C14.2 142.250.191.174:443 ready channel-flow (satisfied (Path is satisfied), viable, interface: en0, ipv4, ipv6, dns)] unregister notification for write_timeout failed

I googled it and they say it’s just ‘noise’… this wouldn’t be an indicator of what I’m doing wrong would it?

Just trying to figure out something I changed my code to this:

        func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
print("#1")
            if let window = (UIApplication.shared.connectedScenes.first?.delegate as? SceneDelegate)?.window {
                print("#1.1")
                if let rootViewController = (UIApplication.shared.connectedScenes.first?.delegate as? SceneDelegate)?.window?.rootViewController {
                    print("#1.2")
                    if let tabBarController = rootViewController as? tommyViewController {
                        print("#1.3")
                        window.rootViewController = tabBarController
                        window.makeKeyAndVisible()
                        print("#2")
                    }
                } else {
                    print("#3")
                    let tabBarController = UIStoryboard(name: "main", bundle: .main).instantiateViewController(identifier: "tommyVC") as? tommyViewController
//                    let viewController:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "tommyViewController") as UIViewController
                    window.rootViewController = tabBarController
                    window.makeKeyAndVisible()
                    print("#4")
//                    self.presentViewController(viewController, animated: false, completion: nil)
                }
            }
            completionHandler()
        }
    }

When I run it I get this in the consul:

#1.1
#1.2
2021-11-20 20:14:59.336724-0600 KBA[13535:4164500] [connection] nw_read_request_report [C1] Receive failed with error "Software caused connection abort"
2021-11-20 20:15:01.140631-0600 KBA[13535:4164177] [connection] nw_endpoint_handler_set_adaptive_read_handler [C9.6 142.250.190.10:443 ready channel-flow (satisfied (Path is satisfied), viable, interface: en0, ipv4, ipv6, dns)] unregister notification for read_timeout failed
2021-11-20 20:15:01.140753-0600 KBA[13535:4164177] [connection] nw_endpoint_handler_set_adaptive_write_handler [C9.6 142.250.190.10:443 ready channel-flow (satisfied (Path is satisfied), viable, interface: en0, ipv4, ipv6, dns)] unregister notification for write_timeout failed
2021-11-20 20:15:01.326647-0600 KBA[13535:4163983] Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified service

So I’m only printing out the 1.2, tells me there must be something wrong with the if let tabBarController = rootViewController as ? tommyViewController { code?

I finally figured it out!!! 3 months of googl’n and ya’s help… thank you so much!

In your bundle (the file navigator on the left) is your storyboard named main.storyboard or Main.storyboard?

Remember that in Swift that upper and lower case names are entirely different, meaning that main and Main are not the same.

I’m assuming that what you want to do is when you receive a notification, is to transition to the TabBarController you have named tommyViewController. Is that correct?

If so then try this simple code in place of your userNotificationCenter function when you receive the notification. I’m taking a stab here so comment out your existing function definition before you add this one.


    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {

        if let window = (UIApplication.shared.connectedScenes.first?.delegate as? SceneDelegate)?.window {
            let tabBarVC = UIStoryboard(name: "Main", bundle: .main).instantiateViewController(withIdentifier: "tommyVC") as? tommyViewController
            guard tabBarVC != nil else { return }

            //  Set it as the root View Controller of the window.
            window.rootViewController = tabBarVC
            window.makeKeyAndVisible()
        }
        completionHandler()
    }

I’ve got an App here in which I am testing (i’m not using Firebase notifications l) just to see if I can switch from a run of the mill ViewController to a TabBarController on the tap of a button and it works. Just not quite sure if the code is correct when used in AppDelegate on receipt of a notification.

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void)
    {
        let userInfo = response.notification.request.content.userInfo
        if let targetValue = userInfo["target"] as? String, targetValue == "value"
        {
            print("userInfo: \(userInfo)")
            coordinateToSomeVC()
        }
        
        completionHandler()
    }

    private func coordinateToSomeVC()
    {
        guard let window = UIApplication.shared.keyWindow else { return }

        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let yourVC = storyboard.instantiateViewController(identifier: "tommyVC")
        
        let navController = UINavigationController(rootViewController: yourVC)
        navController.modalPresentationStyle = .fullScreen

        window.rootViewController = navController
        window.makeKeyAndVisible()
    }
    
}

This is the code I finally got to work. I ‘think’ the view controller is assigned the identifier of tommyVC, but the consol keeps giving me an error that it’s not a view controller in the storyboard, but when I run it, it works the way it should.

OK great. What version of Xcode are you using and what is your target iOS version?

I’m using Xcode 13.0 not sure I have a target iOS… still learning all this stuff here lol

1 Like

Your target iOS is what the lowest version your app is compatible with

Target of iOS 13.0 means your app can run on 13.0 or greater

This is in the project setting by your bundle ID

If you have not specifically selected a target iOS then you are most likely defaulting to iOS 15. You can see where that is set in this screenshot.

Says 14.5