Reputation: 2664
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.
Upvotes: -1
Views: 1158
Reputation: 6324
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:
then configure your website:
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
}
Upvotes: 0