applicationWillEnterForeground Check - ios

In my application ios I have an if that checks if there is internet connection before running the app, if it is offline it sends a screen to retry, the code is as follows below:
if CheckInternet.Connection(){
let url = URL(string: "https://www.example.com/")
let request = URLRequest(url: url!)
webView.load(request)
}
else{
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let secondVC = storyboard.instantiateViewController(withIdentifier: "OffViewController") as! OffViewController
self.navigationController?.pushViewController(secondVC, animated: true)
}
I want to check the connection also when it comes back from the background for first, I read something about applicationWillEnterForeground, but how would the if checking inside that func? On android it is easier to do that but in ios n I have idea

Related

Using Safariservices swift how to code around the small black box

Using SFSafariViewController, works well but for some reason when I go to this webpage [knowitall.ch], it starts up by opening a zoomed view? with a small black box that I need to press to get the full webpage.
My code couldn't be simpler.
if let url = URL(string: url2U) {
let vc = SFSafariViewController(url: url, entersReaderIfAvailable: true)
vc.delegate = self
present(vc, animated: true)
}
If I press the box I get the correct view, how to code around this so I open with the second view here? black box not required :)
That "zoomed view" is the Reader Mode. It shows up because you asked for it. Set entersReaderIfAvailable to false if you don't want it. Also, init(url:entersReaderIfAvailable:) has been deprecated in iOS 11. You need to initialize it with a config object:
if let url = URL(string: url2U) {
let vc: SFSafariViewController
if #available(iOS 11.0, *) {
let config = SFSafariViewController.Configuration()
config.entersReaderIfAvailable = false
vc = SFSafariViewController(url: url, configuration: config)
} else {
vc = SFSafariViewController(url: url, entersReaderIfAvailable: false)
}
vc.delegate = self
present(vc, animated: true)
}

How to Handle Clickable Push Notification In One Signal iOS Swift

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)
}
}

Sceneview freezes when present web view controller

I'm using Safari Services kit to present a web view when an SCNode is clicked. However, when I go back from the safariVC to my VC with the sceneView, the sceneView is frozen even though I restart the session by re-running the session.
I read on this website that presenting another VC kills the scene view thread and I would just like confirmation. Basically I want to know whether it is possible to present another VC and be able to go back to the sceneView and "resume" the scenView
Note:
VC = ViewController
Code
How I present my safari web VC
func presentWebView(){
if let url = URL(string: "https://www.amazon.com/"){
let safariVC = SFSafariViewController(url: url)
self.present(safariVC, animated: true, completion: nil)
}
}
How I restart my session
if let worldSessionConfig = sessionConfig as? ARWorldTrackingSessionConfiguration {
worldSessionConfig.planeDetection = .horizontal
session.run(worldSessionConfig, options: [.resetTracking, .removeExistingAnchors])
}
Use sceneView.session.pause() when you present safariVC and then use sceneView.session.run to restart session when safariVC is dismissed.

Trying to Open SFSafariViewController in AppDelegate via Push Notification

I am trying to open a URL using Safari when the app gets a push notification. This works successfully when the app is in the first viewcontroller. But if the app is further into the program I get an error
<SFSafariViewController: 0x10b20ae60> on <AdViewController: 0x100b14530> whose view is not in the window hierarchy!
(AdViewController is my first view controller, so it is still focused on that one. )
I have searched this site and have tried all the suggestions for this error but have come up short. Currently, my code looks like this:
if MessageUrl != nil , let url = URL(string: MessageUrl!) {
let safari = SFSafariViewController(url: url)
self.window?.rootViewController?.presentedViewController?.present(safari, animated: true, completion: nil)
}
Get top most UIViewController I used extension UIApplication in Appdeleagte from the "swift 3" answer at bottom of that page and changed my code to:
if MessageUrl != nil , let url = URL(string: MessageUrl!) {
let safari = SFSafariViewController(url: url)
UIApplication.topViewController()?.present(safari, animated: true, completion: nil)
}

ios9 - Swift 2.1 - SFSafariViewController

I'm looking to use the SFSafariViewController and have it automatically load a website when the app is opened. Is this possible?
What I have so far (brand new single ios app):
// ViewController.swift
let urlString = "https://stackoverflow.com"
#IBAction func launchSFSafariViewController(sender: AnyObject) {
if let url = NSURL(string: urlString) {
let vc = SFSafariViewController(URL: url, entersReaderIfAvailable: true)
vc.delegate = self
presentViewController(vc, animated: true, completion: nil)
}
}
How do I connect the action to the main view controller via the storyboard? All the articles I see only discuss connecting a button to an action.
Implement viewDidAppear to perform the presentation. (You will need to use a Bool flag, though, to make sure this doesn't happen when you dismiss the presented view controller and viewDidAppear is called again!)

Resources