WWDC22 SALE: Save 50% on all my Swift books and bundles! >>

Link To App Store From UIAlertController

Forums > iOS

How do I link to the App Store from a UIAlertController?

I have a standard NSString text "message" in which I'd like to add a link to an app in the App Store. Any ideas as to how this can be done?

 override func viewWillAppear(_ animated: Bool) {

    let currentVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
    let defaults = UserDefaults.standard
    let storedVersion = defaults.string(forKey: Default.versionKey)
    print ("Stored Version: \(storedVersion ?? "None")")
    print ("Current Version: \(currentVersion ?? "None")")
    if (currentVersion != storedVersion) {
        defaults.setValue(currentVersion, forKey: Default.versionKey) // comment out for testing
        let message = cpu8proVersion.message1_0 + setWarningMessage ()
        showPopupWithTitle(title: "Thank you for using The Product", message: message, interval: 0.5)
    }
}

func setWarningMessage () -> String {
    if (DeviceFamily.IS_IPHONE) {
        return cpu8proVersion.curtesyWarning
    }
    return ""
}

func showPopupWithTitle(title: String, message: String, interval: TimeInterval) {
    let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
    present(alertController, animated: true) {
        let tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.dismissAlertController))
        alertController.view.superview?.subviews[0].addGestureRecognizer(tapGesture)
    }
}

@objc func dismissAlertController(){
    self.dismiss(animated: true, completion: nil)
}

   

All apps on the the store have a https link eg https://apps.apple.com/gb/app/bus-quizzes/id1465159349. if you goto the app store and tap the share button you can find the link.

it looks like that you just want the user to update the app, however this is automatically by Apple as user may have update over wifi only set. Your best bet is just to tell user that updates are available abd if the user wants to update they install it manually.

   

Actually, this is inform users that a new app in a family of apps is available.

How do I provide a URL in the UIAlertController? Can UIAlertController segue to a WKWebKit Controller and automatically use the URL link?

   

You can actually show the store page and update within the app. When user hasn't updated in 10 days my app shows the store page, and when the users closes it it just pops back up, haha. Update you shall!

import StoreKitTest 
func showStorePage() {
    let params = [SKStoreProductParameterITunesItemIdentifier: "123456789"]
    let storeProductVC = SKStoreProductViewController()
    storeProductVC.loadProduct(withParameters: params)
    storeProductVC.delegate = self
    present(storeProductVC, animated: true)
}

//delegate method that gets called when the store page closes
func productViewControllerDidFinish(_ viewController: SKStoreProductViewController) {
    viewController.dismiss(animated: true) {
        showStorePage()
    }
}

I can show the code that checks if there is a new version too if you like.

   

Save 50% in my Black Friday sale.

SAVE 50% To celebrate WWDC22, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

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

Reply to this topic…

You need to create an account or log in to reply.

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.