I have a problem with the implementation of deep links in my app. I am using a notification called accenggage which can be seen here. Once I Start the SDK with the conf set in the AccengageConfig.plist file in my code as indicated in the documentation, ie I do Accengage.start() in the didFinishLaunchingWithOptions method in AppDelegate, I noticed that the function that opens the url is never called. But it will print the payload in my logs, but I cannot get access to it, in order to use it in my code. Everything works perfectly if I comment it. Please have someone used this before to try to see where I go wrong. when I open the link in safari it will lunch the app but will not print the url as I requested and neither will it open the views concerned. I taught my problem was with the deep links implementation, but that is not the case, it is rather the Accengage that I am not using it properly and will be glad if someone could have an approach on how to get the url when the push is sent with Accengage. Thanks!
func application(_ application: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
print("url \(url)")
print("url host :\(url.host as String?)")
print("url path :\(url.path as String?)")
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
if(url.host == "/details"){
let Ads_details: CollectionDetailViewController = mainStoryboard.instantiateViewController(withIdentifier: "CollectionDetailViewController") as! CollectionDetailViewController
self.window?.rootViewController = Ads_details
} else if (url.host == "/profile"){
let User_profil: UserProfileViewController = mainStoryboard.instantiateViewController(withIdentifier: "UserProfileViewController") as! UserProfileViewController
self.window?.rootViewController = User_profil
}
self.window?.makeKeyAndVisible()
return true
}
Related
I already get the data from one signal (additional Data). But I want to present view controller by clicking the push notification itself. Can someone help me. Thanks in advance.
Did you check OneSignal's docs on Deep Linking? https://documentation.onesignal.com/docs/links
There is a demo project on Github that might help you: https://github.com/OneSignal/OneSignal-iOS-SDK/tree/master/Examples
add this in your didFinishLaunchingWithOptions
this code will check that if app was launched using appIcon or tapping on notification
self.window = UIWindow(frame: UIScreen.main.bounds)
let storyBoard = UIStoryboard(name: "Main", bundle: nil)
let tabBar = storyBoard.instantiateViewController(withIdentifier: "MainNavigationController")
as? UINavigationController
self.window?.rootViewController = tabBar
self.window?.makeKeyAndVisible()
if let notification = launchOptions?[.remoteNotification] as? [String: AnyObject] {
// 2
let aps = notification["aps"] as! [String: AnyObject]
let vc = storyBoard.instantiateViewController(withIdentifier: "EmergencyRequestViewController") as? EmergencyRequestViewController
tabBar?.pushViewController(vc!, animated: true)
}
}
I have already read about UIApplication.shared.canOpenURL. But in my case it somehow doesn't work. I have a scheme:
If I have VK app installed, the url vk:// works, and Safari successfully asks me if I want to open this app. On this step, canOpenURL returns true.
If the app is not installed, Safari says, that the url is invalid. But canOpenURL still returns true.
What's going on? Does canOpenURL check only syntax of the URL? Then how must I check if the app is installed?
For open app from deep linking you should also write some lines of code for schema and URL::
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
if(url.absoluteString == "appname://app/https://appurl"){
let defaults = NSUserDefaults.standardUserDefaults()
if defaults.objectForKey("access_token") != nil {
// check condition what you want for open specific page
}
else{
let loginVC: LoginViewController = mainStoryboard.instantiateViewControllerWithIdentifier("LoginViewController") as! LoginViewController
self.window?.rootViewController = loginVC
}
}
self.window?.makeKeyAndVisible()
Please help me in this issue. I have implemented universal links by following https://www.raywenderlich.com/128948/universal-links-make-connection and the problem I am getting is that when I click on a link, I am redirected to web browser instead of app. And in safari browser, when I scroll down the page, I am getting a banner which has OPEN button also. By clicking it, my app opens and the specific view controller according to the logic opens. So why it is opening in browser at first? If app is installed, it should directly open in app instead of web browser.
Following are the methods in my app delegates:
func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool {
if userActivity.activityType == NSUserActivityTypeBrowsingWeb {
guard let url = userActivity.webpageURL else {
return false
}
openViewController(url)
}
return true
}
func openViewController(url: NSURL) {
let components = NSURLComponents(URL: url, resolvingAgainstBaseURL: true)
print(components)
print(url.absoluteString)
if url.host == "refit.co" && (url.pathComponents![2] == "supplements" || url.pathComponents![2] == "equipments") {
print("This is the supplements/equipments universal link")
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("Home")
let navController = self.window?.rootViewController as? UINavigationController
navController?.pushViewController(vc, animated: false)
let vc2 = storyboard.instantiateViewControllerWithIdentifier("SupplementDetail") as? VCSupplementDetail
vc2?.itemID = getID(url.query!)
vc2?.screenName = url.pathComponents![2] == "supplements" ? "Supplements" : "Equipments"
navController?.pushViewController(vc2!, animated: true)
print("Query: \(url.query)")
} else {
print("This is the url: \(url)")
print(url.host)
print(url.path)
print(url.query)
print(url.pathComponents)
}
}
It sounds like you inadvertently deactivated Universal Links. This usually happens if you tap the bypass link in the top right corner of the screen after opening a Universal Link. See this answer for details on how to reverse the process.
Hello Friends My name is Tony dhand. I am new in IOS development. Now i am trying to fix a problem . I am going to login in ios app and after login display the dashboard.
But when i restart the app it again show the login screen. For this i want to change the initialview at the start of the app after login in other words i want to change the view at the startup .I don't know what to do. please help me for resolving this problem or give your idea for this.
Thanks in Advance
When the user logs in successfully you can save the "Login Status" as -
let defaults = NSUserDefaults.standardUserDefaults()
defaults.setBool(true, forKey: "isUserLoggedIn")
defaults.synchronize()
Then in the "AppDelegate.swift" file you can check the login status when the app launches in the "didFinishLaunchingWithOptions" function as -
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let defaults = NSUserDefaults.standardUserDefaults()
let isUserLoggedIn = defaults.boolForKey("isUserLoggedIn")
if(!isUserLoggedIn) {
self.window?.rootViewController = storyboard.instantiateViewControllerWithIdentifier("LoginViewController")
} else {
self.window?.rootViewController = storyboard.instantiateInitialViewController()
}
return true
}
Finally when the user logs out you can change the logged in status as false as -
let defaults = NSUserDefaults.standardUserDefaults()
defaults.setBool(false, forKey: "isUserLoggedIn")
defaults.synchronize()
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.window?.rootViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("LoginViewController")
Hope that helps!
Keep the status of the login in your NSUserDefaults. When you login successfully, then set it as TRUE for the Key.
So Next time when you launch the app, check the value of the variable stored in NSUserDefaults in AppDelegate.
If its true then your Login SUCCESS, then navigate to your dashboardViewController. Otherwise navigate to your login Page ViewController.
Enter the following code after successful login
[[NSUserDefaults standardUserDefaults]setBool:TRUE forKey:#"isLogin"];
Add the following code in your AppDelegate didFinishLaunchingOptions.
if ([[NSUserDefaults standardUserDefaults]boolForKey:#"isLogin"]) {
// Already Logged in
// Set your Dashboard Page as Root View Controller
}
else{
// Not Logged in
// Set your Login Page as Root View Controller
}
Hope it helps...
I am using deep link to open my app from browser. When my app is in background state i can able to open the app and i can able to move to the respective screen based on the URL. But whenever i quit my app, and open the same URL, it is crashing. I have followed Deep link tutorial for creating all actions. And I am moving to another screen in "triggerImp" method. I have added my code below for navigation. Is it rite or do i need to add anything else. Please help me.
let vc = UIViewController()
(appDelegate.window?.rootViewController as! UINavigationController).pushViewController(vc, animated: true)
Is this exact code that you are using? Not sure the app will know what view controller to open if you set it to UIViewController(). Here is how I have it setup that works for both states, background and inactive (using Storyboards):
func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
let storyboard = UIStoryboard(name: mainEntryStoryboardName, bundle: nil)
let newHomeView = storyboard.instantiateViewControllerWithIdentifier("MyView") as! MyViewController
let navigation = MyNavigationController(rootViewController: newHomeView)
self.window!.rootViewController = navigation
return true
}
hope this helps