UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: Day 26: Challenge 1 HELP!!

Forums > 100 Days of Swift

Here is the guts of my code for the webView() method.

let url = navigationAction.request.url

        if let host = url?.host {
            for website in websites {
                if host.contains(website) {
                    decisionHandler(.allow)
                    return
                }
            }
        }
        let alert = UIAlertController(
            title: "Not Allowed",
            message: "Browsing outside of this website is not allowed",
            preferredStyle: .alert)

        alert.addAction(UIAlertAction(
            title: "Ok, I won't do it again.",
            style: .default))

        decisionHandler(.cancel)
        present(alert, animated: true)

I am hitting the decisionHandler(.cancel) line everytime I try to navigate outside the site BUT also when I visit apple.com via the my open button in the navbar. I feel like I've checked everything. It's setup exactly like the tutorial said. It's gotta be something small but I have racked my brain and can't figure it out...

3      

I am convinced there is something with the sites... I just absolutely cannot figure this out and it's like 3 lines of code it's driving me insane...

3      

What is in your websites property?

4      

It's just the line from the tutotial...

var websites = ["apple.com", "hackingwithswift.com"]

3      

For the record, I just changed "apple.com" to "google.com" in my Array of sites I'm passing in and the bug went away. I hadn't considered the data would be wrong but I guess it was.

3      

I had the same issue. It appeard only to be apple.com for me as well. I ended up ignoring it

3      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.