Swift Firebase Dynamic Links: shortenURL not working - ios

facing some issue to generate shortenURL from firebase dynamic-links , I am able to get longDynamicLink url . but
here is my code , I am using https://firebase.google.com/docs/dynamic-links/ios/create following steps DynamicLinkComponents.shortenURL completion not getting call and there is no error also
guard let longDynamicLink = linkBuilder.url else { return "test" }
print("The long URL is: \(longDynamicLink)")
DynamicLinkComponents.shortenURL(longDynamicLink, options: nil) { url, warnings, error in
guard let url = url, error != nil else { return }
print("The short URL is: \(url)")
}
DynamicLinkComponents.shortenURL this part is not executing

Try This Code. This Code Working Fine For Me.
let shareLink:String = "http://YourURL"
guard let newSharelink = URL(string: shareLink) else { return }
let components = DynamicLinkComponents.init(link: newSharelink, domain: "Your Domin From Genrated By Google Account(EX. = napu4u.app.goo.gl)")
let iOSParams = DynamicLinkIOSParameters(bundleID: "YourBundle ID")
iOSParams.appStoreID = "Your AppStore ID (Optional)"
components.iOSParameters = iOSParams
let options = DynamicLinkComponentsOptions()
options.pathLength = .short
components.options = options
components.shorten { (shortURL, warnings, error) in
if let error = error {
print(error.localizedDescription)
return
}
let shortLink = shortURL
print(shortLink)
}

Add this to to App Capabilities - Associated Domains and enter - applinks:yourdomain.com
In your ViewController add
guard let link = URL(string: "https://www.yourdomain.com/share_location.html?Id=\(RandomID)&uid=\(uid)") else { return }
let dynamicLinksDomain = "yourdomain.page.link"
let components = DynamicLinkComponents(link: link, domain: dynamicLinksDomain)
// [START shortLinkOptions]
let options = DynamicLinkComponentsOptions()
options.pathLength = .unguessable
components.options = options
// [END shortLinkOptions]
// [START shortenLink]
components.shorten { (shortURL, warnings, error) in
// Handle shortURL.
if let error = error {
print(error.localizedDescription)
return
}
print(shortURL?.absoluteString ?? "")
self.shortLink = shortURL
}

Related

Send Text and Link to Snapchat from my Swift app without the SDK

I am integrating sharing options from my app to Snapchat.
I have a dynamic URL obtained in an object and clicking the Snapchat's share button directly opens the app if Snapchat is there on the device and show the text with the link. I am using the below code to share which gives an error on Snapchat. Below is my Code.
func shareTextOnSnapchat(obj:VideoData) {
let shaUrl = URL(string: obj.share_url ?? "")
if let myURL:URL = shaUrl{
let promoText = "Check out this great new video from \(obj.name ?? ""), I found on talent app"
let shareString = "snapchat://text=\(promoText)&url=\(myURL)"
let escapedShareString = shareString.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed)!
let url = URL(string: escapedShareString)
UIApplication.shared.openURL(url!)
}
}
I have used this to post video to snapchat. You have option to either post text or a video.
Pod used
pod 'SnapSDK', :subspecs => ['SCSDKCreativeKit']
import SCSDKCreativeKit
var scInstalled = false
override func viewDidLoad() {
super.viewDidLoad()
scInstalled = schemeAvailable(scheme: "snapchat://")
}
func ShowSnapchat(){
if scInstalled {
//shareTextOnSnapchat(obj:videoObj ?? VideoData())
shareFileOnSnapchat(obj:videoObj ?? VideoData())
}else{
downloadSharingAppAlert(appName:"Snapchat")
}
}
func shareTextOnSnapchat(obj:VideoData) {
let shaUrl = URL(string: obj.share_url ?? "")
if let myURL:URL = shaUrl{
let originalString = "\(myURL)"
let escapedString = originalString.addingPercentEncoding(withAllowedCharacters:CharacterSet.urlQueryAllowed)
//let url = URL(string: "snapchat://snap?text=\(escapedString!)")
let url = URL(string: "https://www.snapchat.com/send?text=\(escapedString!)")
if UIApplication.shared.canOpenURL(url! as URL)
{
UIApplication.shared.open(url! as URL, options: [:], completionHandler: nil)
}
}
}
func shareFileOnSnapchat(obj:VideoData){
//// SHARE VIDEO
LoadingOverlay.shared.showLoaderView(view: self.view)
let shaUrl = URL(string: obj.output_vid ?? "")
if let myURL:URL = shaUrl{
let snapVideo = SCSDKSnapVideo(videoUrl: myURL)
let snapContent = SCSDKVideoSnapContent(snapVideo: snapVideo)
// Send it over to Snapchat
snapAPI.startSending(snapContent) { (error) in
if let error = error {
print(error.localizedDescription)
LoadingOverlay.shared.hideLoaderView()
MyCustomAlert.sharedInstance.ShowAlert(vc: self, myTitle: "", myMessage: StringClass.sharedInstance.lcStr_oopsSomethingWentwrong)
} else {
// success
print("Posted to snapchat")
LoadingOverlay.shared.hideLoaderView()
MyCustomAlert.sharedInstance.ShowAlert(vc: self, myTitle: "", myMessage: StringClass.sharedInstance.lcStr_postedToSnapchat)
}
}
}
}
}
func downloadSharingAppAlert(appName:String){
var appStoreURL = "https://apps.apple.com/in/app/snapchat/id447188370"
//Open Appstore for Download
}

SnapSDK integration not working properly, Snapshot shows error: Something went wrong. Please try again later

I followed all the steps from documentation and integrated SnapSDK in my iOS app but when I click the share button in my app it directs me to the snapchat but ends up with an error saying
"Something went wrong please try again later".
private func didTapSnapchatShare(cell: FeedTableViewCell){
print("Share button tapped ")
cell.pauseVideoAndAnimation()
showProgressIndicator(view: self.view)
var watermarkStr = ""
if let userName = cell.cellDataSource?.user?.name {
watermarkStr = userName
}
let promptImage = cell.promptView?.asImage()
cell.slPlayer?.exportVideo(withWatermarkString: watermarkStr, promptImage: promptImage, completionHandler: { status, filePathURL in
DispatchQueue.main.async {
hideProgressIndicator(view: self.view)
if status, let filePathURL = filePathURL {
let url = URL(string: "snapchat://")!
if(!UIApplication.shared.canOpenURL(url)){
if let reviewURL = URL(string: "https://itunes.apple.com/us/app/snapchat/id447188370?mt=8"), UIApplication.shared.canOpenURL(reviewURL) {
if #available(iOS 10.0, *) {
UIApplication.shared.open(reviewURL, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(reviewURL)
}
return
}
}
let video = SCSDKSnapVideo(videoUrl:filePathURL)
let videoContent = SCSDKVideoSnapContent.init(snapVideo: video)
let api = SCSDKSnapAPI(content: videoContent)
api.startSnapping(completionHandler: { (error: Error?) in
print(error?.localizedDescription)
})
}
}
})
}
Check if your file path url is correct or not this happens when we are not using the correct file path sdk will not be able to find the image.

Universal links iOS : open store link if app NOT installed

Have successfully integrated the universal link into app , please guide how can I redirect to store link if app is not installed , please suggest the correct approach to do it thanks
please try this:
guard let link = URL(string: sahareUrl) else { return }
let dynamicLinksDomain = "name.page.link"
let linkBuilder = FIRDynamicLinkComponents(link: link, domain: dynamicLinksDomain)
linkBuilder.socialMetaTagParameters = FIRDynamicLinkSocialMetaTagParameters()
linkBuilder.options = FIRDynamicLinkComponentsOptions()
linkBuilder.options?.pathLength = .short
linkBuilder.socialMetaTagParameters?.imageURL = URL(string: imagename)
linkBuilder.iOSParameters = FIRDynamicLinkIOSParameters(bundleID: "yourBundleId")
linkBuilder.iOSParameters?.appStoreID = "storeId"
linkBuilder.iOSParameters?.iPadBundleID = "yourBundleId"
linkBuilder.androidParameters = FIRDynamicLinkAndroidParameters(packageName: "packageNameOfAndroid")
linkBuilder.socialMetaTagParameters?.title = title
linkBuilder.socialMetaTagParameters?.descriptionText = description
guard let longDynamicLink = linkBuilder.url else { return }
print(longDynamicLink)
FIRDynamicLinkComponents.shortenURL(longDynamicLink, options: nil) { url, warnings, error in
self.runOnUIThread {
if url != nil{
self.shareAds(item: [url!])
}else{
NVActivityIndicatorHelper.hideIndicatorInView()
}
}
}
It may helps you.Thank you

How to get rid of the word optional before a url saved in firebase?

Currently I am saving the url of images stored in the firebase database. However I am getting the word optional before the url. As seen bellow.
"Optional(https:URL.HERE)"
The following is the code block where the saving happens:
if let imageData = UIImageJPEGRepresentation(image, 0.8) {
let metadata = storageRef //.child("poop/")
let uploadTask = metadata.putData(imageData, metadata: nil) { (metadata, error) in
guard let metadata = metadata else {
// Uh-oh, an error occurred!
return
}
// You can also access to download URL after upload.
storageRef.downloadURL { (url, error) in
guard let downloadURL = url else {
// Uh-oh, an error occurred!
return
}
let imgURL = url
//database integration
let ref = Database.database().reference()
let usersRef = ref.child("usersPosts")
let uid = Auth.auth().currentUser?.uid
let newUserRef = usersRef.child(uid!)
//creates a child for email and password (i think we shud store password so we can tell sumone what it is inmediatly, maybe)
newUserRef.setValue(["Image": "\(imgURL)"])
}
}
// For progress
uploadTask.observe(.progress, handler: { (snapshot) in
guard let progress = snapshot.progress else {
return
}
let percentage = (Float(progress.completedUnitCount) / Float(progress.totalUnitCount))
progressBlock(Double(percentage))
})
} else {
completionBlock(nil, "Image could not be converted to Data.")
}
You are getting Optional... because imgURL is optional. And imgURL is optional because you assigned it from url which is optional.
Since you already unwrapped url in the guard statement, just use downloadURL instead of creating imgURL.
Remove:
let imgURL = url
And replace the use of imgURL with downloadURL which is the properly unwrapped version of url from the guard.
newUserRef.setValue(["Image": "\(downloadURL)"])

How to Load audiofile into MMessage ios 10?

so I been playing around the new xcode 8 beta and I'm able to load an image into the .image property but I had not succeed to load an audio file with the .mediaFileURL property.
here's my
var message = MSMessage()
var template = MSMessageTemplateLayout()
viewDidLoad() {
if let filePath2 =
Bundle.main().pathForResource("synth", ofType: "wav") {
let fileUrl = NSURL(string: filePath2)
let URL2 = fileUrl as! URL
template.mediaFileURL = URL2
}
message.layout = template
guard let conversation = activeConversation else {
fatalError("Expected a conversation") } conversation.insert(message,
localizedChangeDescription: nil) { error in
if let error = error {
print(error)
}
}
}
According to bug reporter I should use the insertAttachment API to insert MP3, WAV and M4a.
conversation.insertAttachment(fileUrl, withAlternateFilename: "fileAudio") { error in
if let error = error {
print(error)
}

Resources