I am trying to use the FBSDK, specifically FBSDKShareKit to let users post a deep link to their wall from my app. I have my App set up with Facebook Developers (I know this isn't the issue because my app users sign in with Facebook with no problem) and have a scheme suffix associated with the app.
My application's info.plist has the same suffix set. I know this works because when opening a URL with this suffix from Safari, it navigates to my application.
When opening a URL, my app delegate checks if the URL host matches a certain string, if it does, I then check if the URL path matches a certain string. If both of these match, then I parse the parameters passed from the URL, create a custom object (in this case, an event), instantiate a view controller, and populate that view controller with the custom object's properties.
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
if url.host != "www.mywebsite.app" {
return false
} else if url.path == "/sharedEvent" {
if let parameters = url.queryParameters {
//Get params from url
let name = parameters["name"]!
let description = parameters["description"]!
let lat = parameters["lat"]!.CGFloatValue()
let lng = parameters["lng"]!.CGFloatValue()
let startTime = Int(parameters["startTime"]!)!
let endTime = Int(parameters["endTime"]!)!
let categories = parameters["categories"]!
let priority = Int(parameters["priority"]!)!
let id = parameters["id"]!
let userId = parameters["userId"]!
let userName = parameters["userName"]!
let userEmail = parameters["userEmail"]!
let photoURLs = parameters["photoURLs"]!
let isVerified = Int(parameters["isVerified"]!)
//Create event from parameters
let sharedEvent = Event(name: name, description: description, lat: lat, long: lng, startTime: Date(timeIntervalSince1970: Double(startTime)), endTime: Date(timeIntervalSince1970: Double(endTime)), categories: [categories], priority: priority, id: id, userId: userId, userName: userName, userEmail: userEmail, photoURLs: [photoURLs], isVerified: isVerified!)
//Instantiate eventVC
let storyboard = UIStoryboard(name: "Main", bundle: .main)
let eventVC = storyboard.instantiateViewController(withIdentifier: "EventViewController") as! EventViewController
eventVC.event = sharedEvent
eventVC.userId = userId
eventVC.userEmail = userEmail
eventVC.userName = userName
DispatchQueue.main.async {
self.window!.rootViewController!.presentedViewController?.present(eventVC, animated: true, completion: nil)
}
}
return true
}
This code works as I've tested it by opening a URL from another app with some parameters, and the respective view controller is presented upon the app opening. A URL might look something like this:
fb1068346896678533://www.hootevents.app/sharedEvent?name=Some%20Name&description=Some%20description&lat=38.7016&lng=-90.447&startTime=1548466210&endTime=1551058140&categories=lhw9bs31nr2twlx&priority=1&id=15510581401548012896PfZLZCzDUh&userId=f5qLpyu4XNWa4eJI17sBi71bIw23&userName=David%20Chopin&userEmail=chopindavidg#gmail.com&photoURLs=https://upload.wikimedia.org/wikipedia/commons/thumb/2/2f/Google_2015_logo.svg/1200px-Google_2015_logo.svg.png&isVerified=1
My issue lies with actually presenting the deep link via Facebook. I've tried two approaches:
Using FBSDKShareKit's FBSDKShareButton by setting the button's shareContent to a FBSDKShareLinkContent with a content url equal to the one shown above. Doing this results in a greyed out, i.e. disabled, FBSDKShareButton. Changing the content's URL to something like "www.google.com" enables the button, meaning that Facebook doesn't like my URL for some reason.
let button = FBSDKShareButton()
let shareContent = FBSDKShareLinkContent()
content.contentURL = URL(string: "fb1068346896678533://www.hootevents.app/sharedEvent?name=Some%20Name&description=Some%20description&lat=38.7016&lng=-90.447&startTime=1548466210&endTime=1551058140&categories=lhw9bs31nr2twlx&priority=1&id=15510581401548012896PfZLZCzDUh&userId=f5qLpyu4XNWa4eJI17sBi71bIw23&userName=David%20Chopin&userEmail=chopindavidg#gmail.com&photoURLs=https://upload.wikimedia.org/wikipedia/commons/thumb/2/2f/Google_2015_logo.svg/1200px-Google_2015_logo.svg.png&isVerified=1")
button.shareContent = content
Using iOS's Social framework to instantiate an SLComposeViewController, setting said view controller's URL to the same one above, and presenting the view controller. Upon posting through Facebook, I'm prompted with the error message "There was a problem sharing your link." Again, when replacing the URL in question with "www.google.com," the post goes through successfully, indicating, again, that Facebook doesn't like the deep link I'm providing for some reason.
#IBAction func shareButtonPressed(_ sender: Any) {
let vc = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
vc?.add(loadedImages.first?.image)
vc!.add(URL(string: shareURL))
for photo in self.loadedImages {
vc!.add(photo.image!)
}
present(vc!, animated: true, completion: nil)
}
So, in conclusion, I believe that the issue here lies with the fact that Facebook won't allow me to post:
fb1068346896678533://www.hootevents.app/sharedEvent?name=Some%20Name&description=Some%20description&lat=38.7016&lng=-90.447&startTime=1548466210&endTime=1551058140&categories=lhw9bs31nr2twlx&priority=1&id=15510581401548012896PfZLZCzDUh&userId=f5qLpyu4XNWa4eJI17sBi71bIw23&userName=David%20Chopin&userEmail=chopindavidg#gmail.com&photoURLs=https://upload.wikimedia.org/wikipedia/commons/thumb/2/2f/Google_2015_logo.svg/1200px-Google_2015_logo.svg.png&isVerified=1
on behalf of users. If this is the case, how am I supposed to format my deep link so that users can post it to their wall from my app, effectively sharing events with their Facebook friends and, ideally, driving more traffic to my app?
It seems all I had to do was wait a while (I guess it can take up to 48 hours for the link to start working?).
Note that the Facebook app does not allow users to navigate to another app via universal/deep linking. Their in-app browser is designed to not allow this to happen. There are some workaround, most notably Branch.io, which allows users to get use out of their universal links through Facebook.
Related
I'm creating an app similar to THIS one
I'm working on adding siri shortcuts into my app to get quotes by categories just like this app.
So far I've succeeded in creating NSUserActivity and donating shortcuts. My shortcuts are showing up in spotlight and they work just as expected ( In the overlay window for a shortcut without opening the app)
However, when I show the INUIAddVoiceShortcutViewController and use that to add that shortcut to the shortcuts app, it stops working in the overlay and opens my app instead
The app I'm trying to copy the feature from also has an option to edit their shortcut action which I can't get in my app.
Here is an example of how the app I'm trying to copy shows the sheet, notice the arrow in the 'Do' section
It looks like this when opened
But my app doesn't work like that even though I've set up the intentDefinition file
My app looks like this. I can't for the love of god get it to be editable.
I've read the documentation, read through every tutorial on the web, gone through google's first page completely and still can't find a relevant updated code sample.
This is my IntentDefinition File
I'm donating all available shortcuts as soon as my app opens into the dashboard (I did that to test if I need to donate shortcuts before adding them to siri)
This is my code to generate a new user activity
public let kNewArticleActivityType = "\(bundleID).GetQuotes"
class Shortcuts {
public static func newUserActivity(category: Categories, thumbnail: UIImage? = UIImage(named: "icon")) -> NSUserActivity {
let categoryString = category.getStringValue().capitalized
let invocationPhrase = "\(categoryString) quote"
let attributes = CSSearchableItemAttributeSet(itemContentType: kUTTypeItem as String)
attributes.contentDescription = "Get quote from the \(categoryString) category"
attributes.thumbnailData = thumbnail?.jpegData(compressionQuality: 1.0)
attributes.keywords = ["quote", "motivation", "positive", "vibrations"]
let activity = NSUserActivity(activityType: kNewArticleActivityType)
activity.persistentIdentifier = NSUserActivityPersistentIdentifier(kNewArticleActivityType)
activity.isEligibleForSearch = true
activity.isEligibleForPrediction = true
activity.suggestedInvocationPhrase = invocationPhrase
activity.title = "Get a quote"
activity.userInfo = ["category": categoryString]
activity.contentAttributeSet = attributes
return activity
}
static func donateInteraction(with category: Categories) {
let categoryString = category.getStringValue().capitalized
let phrase = "\(categoryString) quote"
let intent = GetQuotesIntent()
intent.suggestedInvocationPhrase = phrase
intent.category = category
let interaction = INInteraction(intent: intent, response: nil)
interaction.donate { (error) in
if let error = error {
print("Interaction donation failed because \(error.localizedDescription)")
} else {
print("Successfully donated interaction")
}
}
}
}
As soon as a category name is clicked, I add it to siri using this code
func addToSiriClicked(category: String) {
let categoryEnum = Categories.getEnum(from: category)
let activity = Shortcuts.newUserActivity(category: categoryEnum)
self.userActivity = activity
let shortcut = INShortcut(userActivity: activity)
let viewController = INUIAddVoiceShortcutViewController(shortcut: shortcut)
viewController.modalPresentationStyle = .formSheet
viewController.delegate = self
self.present(viewController, animated: true, completion: nil)
}
If anyone can find any relevant tutorial for ios 14 or for siri shortcuts that isn't 2 years old, please send me a link. My donations work as expected from the spotlight, but they are generated as another interaction when I add them to siri and they stop working and open the app from that shortcut.
To get the edit function, you have to initialize the INUIAddVoiceShortcutViewController class with your custom intent
It has 2 initializers, 1 for the user activity and another one for a custom intent. Using the intent initializer solved this issue for me.
let shortcut = INShortcut(intent: Shortcuts.newIntent(category: categoryEnum))
if let shortcut = shortcut {
INVoiceShortcutCenter.shared.setShortcutSuggestions([shortcut])
let viewController = INUIAddVoiceShortcutViewController(shortcut: shortcut)
viewController.modalPresentationStyle = .formSheet
viewController.delegate = self
self.present(viewController, animated: true, completion: nil)
}
I am using universal link in iOS application. For the universal link I am using of Firebase dynamic link.
Universal link is working fine when app is installed. But when app is not installed then this link is opening in safari.
I am creating dynamic link (Universal link) programatically in Swift.
func createDynamicLinkForConsumer(){
guard let link = URL(string: "https://<Domain-Name>?consumerID=\(Auth.auth().currentUser?.uid ?? "")&type=consumerReferral") else { return }
let dynamicLinksDomainURIPrefix = "<appName>.page.link"
let linkBuilder = DynamicLinkComponents(link: link, domain: dynamicLinksDomainURIPrefix)
linkBuilder.options?.pathLength = .short
linkBuilder.iOSParameters = DynamicLinkIOSParameters(bundleID: "<Bundle-ID>")
linkBuilder.iOSParameters?.appStoreID = "<app-store-id>"
linkBuilder.androidParameters = DynamicLinkAndroidParameters(packageName: "<android package name>")
linkBuilder.navigationInfoParameters?.isForcedRedirectEnabled = true
guard let longDynamicLink = linkBuilder.url else { return }
print("The long URL is: \(longDynamicLink)")
self.referralLinkLabel.text = String(describing: longDynamicLink)
DynamicLinkComponents.shortenURL(longDynamicLink, options: nil) { (url, warnings, error) in
if url != nil {
print("Short URL is: \(url)")
self.referralLinkLabel.text = String(describing: url!)
}
}
}
This is the screen which opens after when safari opens the link:
After tapping on "Open" button of alert box browser opens app store app.
Actually what I would like to do is to redirect and go to the app store, so users can download the app directly. I don't want to this two steps to open app store.
You should first init DynamicLinkNavigationInfoParameters, then set property to true.
linkBuilder.navigationInfoParameters = DynamicLinkNavigationInfoParameters()
linkBuilder.navigationInfoParameters?.isForcedRedirectEnabled = true
Hi you can reduce these steps with this check on the dynamic link
But you should have in mind that you can have a problem with your link in Messanger app and some other apps.
Hi in my project we are using Deep-linking.
when the user tap on email template user needs to go to concern page in mobile app.
by using of template I getting link like this:
TaptoSchedule://host/inner
But backend people are giving link like : https://www.laundry.com/new-schedule/
How to we getting this type of functionalities in iOS please share any idea with me.
I follow this: http://swiftdeveloperblog.com/deep-linking-using-custom-url-scheme/
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
if defaultValues.value(forKey: accessToken) != nil{
let urlPath : String = url.path as String
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
//TaptoSchedule://host/inner
if(urlPath == "/inner"){
let innerPage: PickupController = mainStoryboard.instantiateViewController(withIdentifier: "PickupController") as! PickupController
innerPage.selectedfrom = "Deeplink"
self.window?.rootViewController = innerPage
} else if (urlPath == "/about"){
}
self.window?.makeKeyAndVisible()
return true
}else{
setRootControllerBeforeLogin()
return true
}
}
You have to talk to backend people to call
TaptoSchedule://host/inner
after user visit https://www.laundry.com/new-schedule/ in order to open your app
You probably want to use Universal Links instead of Deep Links. Universal Links use the standard URL format which appears to be what your backend team is providing for you.
From a customer perspective the experience is essentially the same between Deep Links and Universal Links. However, Universal Links give you some additional flexibility. For example, Universal Links use the standard URL format, which can link to a webpage in cases where your user does not have your application installed.
Check out the Apple documentation here for details:
https://developer.apple.com/ios/universal-links/
https://developer.apple.com/documentation/uikit/inter-process_communication/allowing_apps_and_websites_to_link_to_your_content/enabling_universal_links
In order to open instagram app with certain post I'm using following code:
func instaOpen(_ postId: String, _ postUrl: String){
let appURL = URL(string: "instagram://media?id=\(postId)")!
if UIApplication.shared.canOpenURL(appURL) {
UIApplication.shared.open(appURL, options: [:], completionHandler: nil)
} else {
// if Instagram app is not installed, open URL inside Safari
let webURL = URL(string: postUrl)!
let svc = SFSafariViewController(url: webURL)
present(svc, animated: true, completion: nil)
}
}
When instaOpen function called – instagram app opens, but login prompt forcefully pops over. Not matter what you do - close it or proceed with login, the queried post simply won't open(see gif).
This started happening recently, after I've updated my app and pushed deployment target to iOS12.
I do have instagram listed in my LSApplicationQueriesSchemes as well as I'm 100% positive that correct mediaID is being passed to instaOpen func (the code worked previously).
Let me know if there's any suggestions on how to fix this and actually open instagram post in instagram app.
Updated - Facebook developer fixed the issue.
Its instagram bug you can follow its progress from https://developers.facebook.com/support/bugs/290173615155052/?disable_redirect=0
Probably a bug, as that feature works on Android.
i manage to "fix" the problem on a pwa app using the Instagram web app.
let appURL = URL(string: "https://www.instagram.com/p/\(postId)")!
//https://www.instagram.com/p/insert here media id
I am developing an iOS application with a button to report an issue using SMS/iMessage. I am using MFMessageComposeViewController to present the message composition interface using the following code (Swift 3):
if(MFMessageComposeViewController.canSendText()){
let controller = MFMessageComposeViewController()
controller.messageComposeDelegate = self
controller.body = "Example Message"
controller.recipients = ["2345678901"]
self.present(controller, animated: true, completion: nil)
}
I have also implemented the MFMessageComposeViewControllerDelegate function to dismiss properly. A standard text message / iMessage sends successfully, but the user does not have the option to attach an image. The buttons for camera, iMessage Apps, etc. are there, but they are disabled and cannot be pressed. How can I enable these buttons (camera, specifically) to allow my users to attach images to messages composed with the app?
The Buttons in Question:
EDIT:
Thanks Abdelahad for the suggestion. I've modified his response to allow multiple recipients and to include a message body. I also updated it to remove the deprecated addingPercentEscapes(using: ) method.
Here is a solution using a url to open the Messages app. NOTE: This takes users out of the app.
let recipients = "2345678901,3456789012" //Phone Numbers
let messageBody = "This is a test"
let sms: String = "sms://open?addresses=\(recipients)&body=\(messageBody)"
let smsEncoded = sms.addingPercentEncoding(withAllowedCharacters: .urlFragmentAllowed)
let url = URL(string: smsEncoded!)
UIApplication.shared.openURL(url!)
But still I would like a solution that does not take the user out of the app. Is this possible? Why would the MFMessageComposeViewController show the buttons without enabling them?
Don't use MFMessageComposeViewController use UIApplication.shared.openURL(url!) but this will takes the user out of the app
var phoneToCall: String = "sms: +201016588557"
var phoneToCallEncoded = phoneToCall.addingPercentEscapes(using: String.Encoding.ascii)
var url = URL(string: phoneToCallEncoded)
UIApplication.shared.openURL(url!)