-1

I need to add the in-app events which need to redirect to the Purchase screen.

How can I achieve this?

Note: I can able to open the app using the universal link. But can't able to open the Purchase screen using the link.

3

1 Answer 1

0

If the payload comes from a push notification then you can use DEEP LINKING. If you want to tap on an address like www.myWevSite.com/purchase/123456 and open the app if installed, then you can use UNIVERSAL Linking.

To use Universal Linking you first need to:

  1. Enable Associated Domains on your app identifier.
  2. Enable Associated Domains on your Xcode project.
  3. Add the proper domain entitlement.
  4. Make sure the entitlements file is included at build.

then configure your website:

  1. a SSL certificate
  2. Create structured apple-app-site-association JSON file. (check this)... it's something like www.yourWebsite.com/apple-app-site-association

Facebook for instance has the same file at https://facebook.com/apple-app-site-association

Once everything is setup correctly, if you click on the link, the associated domain is checked and, if the app is installed, you can navigate the user to any view controller in the app.

For instance your email button can have the following link: https://www.website.com/login?data=yourDate

so in the app you can do the following:

func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
    // 1
    if let url = userActivity.webpageURL {
        var parameters: [String: String] = [:]
        URLComponents(url: url, resolvingAgainstBaseURL: false)?.queryItems?.forEach {
            parameters[$0.name] = $0.value
     }

     if let data = parameters["data"] {
        // validate your data and navigate to wherever you like
     }   
   }
}

If you want to use DEEP LINK, you need to add the payload in your push notification and then do something like this:

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

    let userInfo = response.notification.request.content.userInfo
    guard  let kind =
            userInfo["kind"] as? String else {
                return } // if you have it in the payload, maybe you can use it to handle different kinds of push notifications with an enum... see below for an example


    guard  let payload = userInfo["payload"] as? [String: AnyObject]  else { return }

    switch NotificationMessageKind(rawValue: kind) {
       case like: 
          //Use your payload to handle navigation
       case comment: 
          //Use your payload to handle navigation
       default:
          //Use your payload to handle navigation            
     }
}

enum NotificationMessageKind: String, Codable {
    case like = "like"
    case comment = "comment"
    case followed = "follow"
    case commentReply = "reply"
    case unknown
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.