I updated Firebase Dynamic Link pod to 1.4 version. In this version I found very useful class named FIRDynamicLinkComponents. I decided to use it to generate dynamic links. But I have 2 problems:
Firebase doc says that dynamic links can survive installation process and open app on the content I described in dynamic link after installation from AppStore. It is not work.
When user without installed app taps on dynamic links, he will see strange screen with button "Open in App". After click AppStore appears.
Can we skip this screen?
My implementation:
static func createDynamicLinks(forChallangeId challangeId: String, authorId: String, authorEmail: String, completion: #escaping (_ dynamicLink: String?, _ error: Error?) -> Void) {
let link = URL(string: "https://CODE.app.goo.gl/challange/\(challangeId)/author/\(authorId)")!
let domain = DOMAIN
let components = FIRDynamicLinkComponents(link: link, domain: domain)
//add iOS params
let iOSParams = FIRDynamicLinkIOSParameters(bundleID: bundleId)
iOSParams.appStoreID = APP_STORE_ID
components.iOSParameters = iOSParams
//add Android params
let androidParams = FIRDynamicLinkAndroidParameters(packageName: PACKAGE_NAME)
androidParams.minimumVersion = 19
components.androidParameters = androidParams
//add social meta tag params
let socialParams = FIRDynamicLinkSocialMetaTagParameters()
socialParams.title = "You got new challenge"
socialParams.descriptionText = "\(authorEmail) sent the challenge to you."
socialParams.imageURL = IMAGE_URL
components.socialMetaTagParameters = socialParams
//add options
let options = FIRDynamicLinkComponentsOptions()
options.pathLength = .short
components.options = options
//make link shorter
components.shorten { (shortURL, warnings, error) in
if let error = error {
completion(nil, error)
return
}
guard let shortLinkString = shortURL?.absoluteString else {
completion(nil, error)
return
}
completion(shortLinkString, error)
}
}
Edit
3rd problem.
Target iOS10. Handle:
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: #escaping ([Any]?) -> Void) -> Bool {
guard let dynamicLinks = FIRDynamicLinks.dynamicLinks() else {
return false
}
let handled = dynamicLinks.handleUniversalLink(userActivity.webpageURL!) { (dynamiclink, error) in
if let url = dynamiclink?.url {
DynamicLinksManager.handleDeepLink(link: url)
}
}
return handled
}
handled is true but in closure dynamiclink and error are nil.
A lot of solutions depend on having more context than you've currently included. I'll edit this answer with updates as possible.
Dynamic Links definitely can survive the installation process in most situations. However, there are a lot of edge cases. Could you add specific reproduction steps for exactly the process you're using to test?
No, unfortunately this modal cannot be skipped. Apple made some changes in iOS 10.3 that make something like this unavoidable (read here for more on what happened, and how we handled the same problem in a slightly more elegant way at Branch)
This might be expected, if no valid Dynamic Link were triggered. Again, could you add specific reproduction steps?
Related
Is there anything else on iOS like getExternalStorageDirectory() ?
Is it getApplicationDocumentsDirectory() ?
If so, can the user access it?
The files in getApplicationDocumentsDirectory() can be shown as a list in the flutter iOS app?
use the path package, supported on all main os
https://pub.dev/packages/path
Unfortunately, you cannot access other app directories except for yours in iOS because of sandboxing. You can read it here as well:
https://developer.apple.com/documentation/uikit/view_controllers/providing_access_to_directories
By the way, there is a way to get other directories using swift as provided in the documentation, but I did not see any solution for it using flutter.
Hope it helps you.
If I'm not mistaken, you are trying to get another application directory in iOS using flutter.
There is a way to do so.
At first, let me mention that you do not need any permission for writing & reading data in iOS. It is given by default. But, the problem is getting their path. As others already mentioned that, iOS uses sandboxing, you cannot directly get access to all files and folders excluding shared storage.
Steps you need to do for reading and writing directories of other apps.
Install file_picker package. Link: https://pub.dev/packages/file_picker
Using it, popup system directory picker:
String? selectedDirectory = await FilePicker.platform.getDirectoryPath();
PS: Users should know which folder they need to get an access.
3. When they select the folder, get the folder path and use it as you want. But there is still one thing to complete. You need to use a little bit Swift code for getting access it.
import UIKit
import Flutter
import Photos
#UIApplicationMain
#objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
let batteryChannel = FlutterMethodChannel(name: "example.startAccessingToSharedStorage",
binaryMessenger: controller.binaryMessenger)
batteryChannel.setMethodCallHandler({
[weak self] (call: FlutterMethodCall, result: FlutterResult) -> Void in
// This method is invoked on the UI thread.
guard call.method == "startAccessingToSharedStorage" else {
result(FlutterMethodNotImplemented)
return
}
print("\(call.arguments)")
self?.startAccessingToSharedStorage(result: result, call: call)
})
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
private func startAccessingToSharedStorage(result: FlutterResult, call: FlutterMethodCall) {
let args = call.arguments as? Dictionary<String, Any>
if(args != nil){
let fileUrl = URL(fileURLWithPath: (args!["url"] as? String) ?? "")
// Get bookmark data from the provided URL
let bookmarkData = try? fileUrl.bookmarkData()
if let data = bookmarkData {
// Save data
} else {
result("Some bad thing happened")
}
// Access to an external document by the bookmark data
if let data = bookmarkData {
var stale = false
if let url = try? URL(resolvingBookmarkData: data, bookmarkDataIsStale: &stale),
stale == false,
url.startAccessingSecurityScopedResource()
{
var error: NSError?
NSFileCoordinator().coordinate(readingItemAt: url, error: &error) { readURL in
if let data = try? Data(contentsOf: readURL) {
result("Error occured while getting access")
}
}
result("\(url.startAccessingSecurityScopedResource())\(args!["url"])")
}
}
} else {result("\(args!["url"])")}
}
}
Use method channel for using this function in flutter.
Yes, on iOS in order to get path set import:
import 'package:path_provider/path_provider.dart' as syspath;
then use:
final appDir = await syspath
.getApplicationDocumentsDirectory();
if you save the path, keep in mind that on iOS the path changes every time we run the application.
I have an Instagram scheduling app and I am trying to open this (see image below) in Swift 5.x. The goal is simple: save Image to Firebase, once it is time to post, notification!, user clicks on the notification and this (image below) opens up with the appropriate image/video to post. Everything works except for opening Instagram with the appropriate photo/video. I have tried this:
func postToInstagram(image: URL) {
let videoFileUrl: URL = image
var localId: String?
PHPhotoLibrary.shared().performChanges({
let request = PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: videoFileUrl)
localId = request?.placeholderForCreatedAsset?.localIdentifier
}, completionHandler: { success, error in
// completion handler is called on an arbitrary thread
// but since you (most likely) will perform some UI stuff
// you better move everything to the main thread.
DispatchQueue.main.async {
guard error == nil else {
// handle error
print(error)
return
}
guard let localId = localId else {
// highly unlikely that it'll be nil,
// but you should handle this error just in case
return
}
let url = URL(string: "instagram://library?LocalIdentifier=\(localId)")!
guard UIApplication.shared.canOpenURL(url) else {
// handle this error
return
}
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
})
}
and this:
func postToInstagram(image: URL, igURL: String) {
let urlStr: String = "instagram://app"
let url = URL(string: igURL)
if UIApplication.shared.canOpenURL(url!) {
print("can open")
UIApplication.shared.open(url!, options: [:], completionHandler: nil)
}
}
To no avail. The latter code works, but only opens the Instagram app itself, which is fine, but I would like to open the View in the image below rather than Instagram's home screen. I also tried changing the URL to "instagram://share" and this works but goes to publish a regular post, whereas I want the user to decide what they want to do with their image.
This is where I want to go:
Note: For everyone who will be telling me this and whoever will wonder: Yes, my URL schemes (LSApplicationQueriesSchemes) are fine. And, just to clarify, I need to fetch the image/video from Firebase before posting it.
On iOS 14 using SwiftUI, I'm currently trying to test Dynamic Links in the situation where the user clicks the link and installs the app, then opens it up and receives information from that link. I followed the recommendations in this post (How can I test Firebase Dynamic Links if my app is not in the App Store?) and also implemented all the AppDelegate functions on the Firebase iOS website.
However, nothing gets called when I open the link, install the app, and then open the app for the first time (It just says "Pasted from Safari"). The only thing that works is clicking Dynamic links when the app is already installed (it opens up the app and calls the url listener functions correctly).
This is the code for generating the link:
let dynamicLink = URL(string: "http://www.mydomainishereIjustremovedit.com/?referrer=\(referrerID)")!
//guard let uid = Auth.auth().currentUser?.uid else { return }
if let referralLink = DynamicLinkComponents(link: dynamicLink, domainURIPrefix: "https://penciltestapp.page.link") {
referralLink.iOSParameters = DynamicLinkIOSParameters(bundleID: "com.penciltestapp.penciltestapp")
//referralLink.iOSParameters?.minimumAppVersion = "1.0"
referralLink.iOSParameters?.appStoreID = "962194608" // Opens up a random app on the app store. Just click this to open the app store, and then install your app from XCode
referralLink.shorten { (shortURL, warnings, error) in
if let error = error {
print(error.localizedDescription)
return
}
self.inviteURL = shortURL
}
}
Dont' forget to implement also this, this was missing in my case
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any]) -> Bool {
return application(app, open: url,
sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
annotation: "")
}
I created the DynamicLink for my firebase project when I am trying to receive the link I am getting "That's weird. My dynamic link object has no url".
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: #escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
if let incomingURL = userActivity.webpageURL{
print("Incoming URL is \(incomingURL)")
let linkHandled = DynamicLinks.dynamicLinks().handleUniversalLink(incomingURL)
{(dynamicLink, error) in
guard error == nil else{
print("Found an error! \(error!.localizedDescription)")
return
}
if let dynamicLink = dynamicLink{
self.handleIncomingDynamicLink(dynamicLink)
}
}
if linkHandled{
return true
}
else{
return false
}
}
return false
}
func handleIncomingDynamicLink(_ dynamicLink: DynamicLink){
guard let url = dynamicLink.url else{
print("That's weird. My dynamic link object has no url")
return
}
print("Your incoming link parameter is\(url.absoluteString)")
}
After checking all the blogs and posted this issue on firebase, I didn't find any solution for this but I came up with this concrete solution and it will work definitely
here: dynamicLinkURL is your main dynamic link and shortHandURL is your deeplink URL which is associated with your dynamic link. I hope the below snippet will help you.
func dynamicLinkhandler(_ dynamicLinkURL: URL, onCompletion: #escaping(_ success: Bool) -> Void) {
URLSession.shared.dataTask(with: dynamicLinkURL) { (data, response, error) in
guard error == nil else {
print("Found Error \(String(describing: error?.localizedDescription)))")
return
}
guard let shortHandURL = response?.url, shortHandURL != dynamicLinkURL else {
print("Thats Weird, my dynamic link has no URL")
onCompletion(false)
return
}
onCompletion(true)
}.resume()
}
Double check that the bundle id you set up in the dynamic link wizard creation within the firebase console it's the one you are running the app into.
I have three different bundle ids (dev, enterprise, production) and, for instance, if a set in the link the production bundle id but the app runs the dev bundle id, instead of returning back some error it returned an honest dynamicLink object but with a nil value in the url.
I created a keyboard extension with a scan button to open a barcode scanner in my containing app. When the scan is completed, it should navigate back to the initial app and the barcode data should be set as text to the textfield that initiated the keyboard and we clicked on scan button.
There is this app Scandit Wedge that does it the same way. But I couldn't find a way to achieve the same.
Please refer GIF below.
https://s3.amazonaws.com/id123-dev-ios/scandit.gif
Any help would be much appreciated.
There is no public API to switch to the previous app, here is the answer: https://stackoverflow.com/a/13447282/1433612
But you could do that if you know the app's bundle id and url scheme. You can find unofficial lists on internet. Assuming that you are able to recognize the source app you can do something like this in your AppDelegate:
public func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
guard let applicationBundleId = options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String else {
return true
}
// Save your source application
sourceApplicationBundleId = applicationBundleId
return true
}
var sourceApplicationBundleId: String?
// Attempt to open application from which your app was opened
func openApplication() {
guard let applicationBundleId = sourceApplicationBundleId, let url = url(for: applicationBundleId) else {
return
}
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
func url(for bundleId: String) -> URL? {
guard let scheme = knownUrlSchemes[bundleId] else {
return nil
}
return URL(string: scheme)!
}
// A list of known url schemes
var knownUrlSchemes: Dictionary<String, String> = {
return ["com.google.Maps": "comgooglemaps://",
"com.facebook.Facebook": "fb://"]
}()