iOS universal links not entering in UIApplicationDelegate callback - ios

I'm trying to use universal links to be detected in a callback in an app developed in SwiftUI. I think all the settings are ok, including the AASA file, capability in the app with applinks: join-domain.com. When I tap in the link https://join-domain.com/something in the notes app it will open my app so I assume is detecting the domain but it never enters in any callback of the appDelegate.
Inside the app I have the following:
import SwiftUI
#main
struct XApp: App {
#UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
and in AppDelegate:
class AppDelegate: UIResponder, UIApplicationDelegate, ObservableObject {
func application(_ application: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler: #escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
print("did it entered here?")
}
}
I run through stackoverflow, nothing worked. In this one thread it mentions the 'Application Scene Manifest' and configurationForConnectingSceneSession. I have nothing of that.
Any ideas?

Related

Firebase app check not working with iOS 16

It looks like for my app the firebase app check is not working with iOS16. I have configured the app attest and its been working for more than a year, it's still working with older iOS versions but not iOS 16.
This is the code that I initialise app check
import SwiftUI
import Firebase
import FirebaseAppCheck
#main
struct appointmeparterAppApp: App {
#Environment(\.scenePhase) var scenePhase
#UIApplicationDelegateAdaptor(AppDelegate.self) var delegate
init() {
let providerFactory = YourAppCheckProviderFactory()
AppCheck.setAppCheckProviderFactory(providerFactory)
FirebaseApp.configure()
}
}
class YourAppCheckProviderFactory: NSObject, AppCheckProviderFactory {
func createProvider(with app: FirebaseApp) -> AppCheckProvider? {
return AppAttestProvider(app: app)
}
}
I am sure the problem is app check because if it's not enforced everything works as expected, and if I enforce it then i get permissions error. (this happens only on iOS 16)
import SwiftUI
import Firebase
import FirebaseCore
import FirebaseAppCheck
class AppDelegate: NSObject, UIApplicationDelegate {
let providerFactory = ACFTAppCheckProviderFactory()
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
AppCheck.setAppCheckProviderFactory(providerFactory)
FirebaseApp.configure()
return true
}
}
#main
struct ACFTApp: App {
#UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
class ACFTAppCheckProviderFactory: NSObject, AppCheckProviderFactory {
func createProvider(with app: FirebaseApp) -> AppCheckProvider? {
return AppAttestProvider(app: app)
}
}
Set the App attest env. to production. Ensure you add App Attest capability to your app target. Remove the -FIRDebugEnabled in your app scheme/run/arguments. Possibly ensure you add the debug token to your registered apps/manage tokens on FB.

Open url from Firebase In-App-Messaging inside app

I'm trying to override Firebase's default behavior for opening the link from the In-App-Messaging following this guide:
https://firebase.google.com/docs/in-app-messaging/modify-message-behavior?platform=ios
I set the delegate of InAppMessaging in AppDelegate:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
InAppMessaging.inAppMessaging().delegate = self
}
I add my logic in the Delegate method:
extension AppDelegate: InAppMessagingDisplayDelegate {
func messageClicked(_ inAppMessage: InAppMessagingDisplayMessage, with action: InAppMessagingAction) {
let topMostViewController = UIApplication.shared.topMostViewController()
//openUrl has logic for opening the url inside the app in a full screen webview FullScreenWKWebView, this works great
openUrl(action.actionURL, parent: topMostViewController)
}
When tapping the button in the InAppMessaging message the delegate method messageClicked is loaded perfectly and also the logic for opening the url inside the app works. BUT also the default logic from Firebase for opening the link continues so the url is opening inside the app and at the same time Firebase jumps out of the app and open the url in Safari.
Is there some way I can cancel the default logic from Firebase so that it only opens inside the app?
For HTTP links, you can intercept URL opening in the handoff:
// UIApplicationDelegate
func application(_ application: UIApplication, continue userActivity: NSUserActivity,
restorationHandler: #escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
// handle userActivity.webpageURL
// true, if handled
return true
}

Running code when app is terminated. Xcode 12

I'm trying to run some code to refresh data and serve a local notification on iOS 14. I'm using Xcode 12 and all the help I find online is based on a structure having an appdelegate.swift swift file with several functions depending on the state of the app.
In Xcode 12 the appdelegate file isn't there anymore. How do I proceed, I don't know where to start. Does anybody know what to do?
Your issue is probably that you set up the project to use SwiftUI. You need to create an AppDelegate object that implements UIApplicationDelegate protocol:
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
print("Your code here")
return true
}
// Implement other methods that you require.
}
On your SwiftUI file, add this line to tell iOS who's gonna be the listener for the AppDelegate's methods:
#main
struct SomeApp: App {
#UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
You can then follow by checking Apple's documentation on how to use background app modes.

URL Opening Swift App - Open Works - Called Function Does NOT work

Hello All – I am a newbie here ... trying to get my first iOS Swift (Xcode 11.2.1 / Swift 5 / iOS 13.2) app to open via URL and process the URL string. The app opens just fine, but the function (method?) does not appear to be getting called. Here's what I've got:
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
print("Here I iz ... in the URL responding bit.")
print(url)
return true
}
...
That code is in the AppDelegate.swift file in my project.
And that is what I have in my Info.plist file.
I launch via Safari both on-device and in the simulator with confirmevent://HelloWorld
As I said ... The app is opening, but I do not see any results from my print statements in the Xcode debug area.
In searching other posts they said that I need to use the "Wait for executable to be launched" to attach Xcode to the app, which I have done and it is indeed attaching. BUT I notice that none of my dozens of print statements that I have scattered about in my app appear when either when opening via "wait for executable to be launched" option.
Any/All help would be appreciated. I've spent over 5 hours scouring the web, but all indications are that is should "just work"
I just found a solution here: application(...continue userActivity...) method not called in ios 13
The trick is to also implement the SceneDelegate.swift functions for Apps with iOS > 13. This function should be called if you open the URL confirmevent://HelloWorld:
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
print(URLContexts.debugDescription)
}
WindowGroup {
SampleView()
.onOpenURL { url in
//this url that was opened by your app
}
}
}
you need to use this function in your appDelegate
func application(_ application: UIApplication, continue userActivity: NSUserActivity,
restorationHandler: #escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
if let incomingURL = userActivity.webpageURL {
print(incomingURL)
}
return false
}

Handling tel: links in voip app

Is there any method in iOS (CallKit? perhaps) where a VoIP app can register to handle tel: links? That way when a user selects a phone number (in safari for instance). They would be presented with two options to complete the call.
This is supported in iOS these days if you press and hold on a tel: link. It doesn't use the standard URI scheme system, though. CallKit seems to automatically register your app as a handler of tel: links if you declare support for phone calls, and the link is passed through the following event:
import Intents
protocol SupportedStartCallIntent {
var contacts: [INPerson]? { get }
}
extension INStartAudioCallIntent: SupportedStartCallIntent {}
extension INStartVideoCallIntent: SupportedStartCallIntent {}
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, CXProviderDelegate {
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: #escaping ([Any]?) -> Void) -> Bool {
let interaction = userActivity.interaction
let startCallIntent = interaction?.intent as? SupportedStartCallIntent
if let contact = startCallIntent?.contacts?.first?.displayName {
// do what you want with 'contact'
}
return true
}
That capability does not exist in iOS today. If you are interested in that, I recommend filing a bug report to request it on Apple's Bug Report website.

Resources