I am getting URL schemes error while archiving my iOS app - ios

This is the error -
The following URL schemes found in your app are not in the correct formats.Please see RFC1738 for more detail.
This is my code -
#IBAction func webdropbox1(_ sender: Any) {
let safariVC = SFSafariViewController(url: NSURL(string: "www.dropbox.com")! as URL)
self.present(safariVC, animated: true, completion: nil)
safariVC.delegate = self
}
Also I have added the URL to my info.plist file -
Info.plist file screenshot:

A URL scheme is the part before the colon: http, https, ftp, mailto, file, etc.
www.dropbox.com is not a URL scheme. It's not even a valid URL.
You have two issues.
Your Info.plist needs to be updated to specify actually valid schemes, not a partial URL.
Your code to create the Dropbox URL needs to use "https://www.dropbox.com".

Related

Choose what share actions get what content with UIActivityViewController

I am currently using UIActivityViewController to share an url to other apps. This part works fine.
But when I'm sharing to an app like iMessage, Whatsapp or Mail. I would like to add a string.
Example:
Sharing -> airdrop: https://www.google.com
Sharing -> iMessage: "Hi there, checkout this cool website: https://www.google.com"
I tried to do it by adding both an Url object and a String into the UIActivityViewController like so:
let url = URL(string: "https://www.google.com)
let text = "Hi there, checkout this cool website: \(url)"
let items: [Any] = [url, text]
let controller = UIActivityViewController(
activityItems: items,
applicationActivities: nil)
DispatchQueue.main.async{self.present(controller, animated: true, completion: nil)}
^not the actual code, but enough to draw a picture
This does work with Airdrop, it opens the url.
It also works in Mail, it uses the string containing the url.
It doesn't work however in iMessage. iMessage takes both and combines them like so:
https://www.google.com Hi there, checkout this cool website: https://www.google.com
Does anyone have any suggestions for me to keep the functionality for Airdrop/Mail etc. But for it to also work on iMessage?
Use a UIActivityItemSource. The UIActivityItemSource is told the identifier of the requesting process, so you can refrain from handing the URL to Messages and hand it just the string, which is sufficient.

How to add a attachment in outlook programatically swift 3

I have opened the outlook app and send a file in it. I am able to open the outlook and set the To,Subject and Body but not sure how to attach file in the document directory
The file is at path
var paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
let documentsDirectory = paths[0]
let fileName = "supportdata.log"
let logFilePath = (documentsDirectory as NSString).appendingPathComponent(fileName)
let scheme : String = "ms-outlook://compose?tosupport#tech.com&subject=Support data &body=Please find the attached file"
if let url = URL(string: scheme) {
UIApplication.shared.open(url, options: [:], completionHandler: {
(success) in
if (success)
{
print("Open \(scheme): \(success)")
}
})
}
Sadly, it is not possible. There are two main issues:
You are deeplinking to an app, meaning sending an on-device message to another app that is effectively the same as a normal URI with a GET method parameterized string. String only, no major data/files can be sent. The URL Scheme below is for reference. And it is the same as what you're using; though I think you are missing an '=' in your ms-outlook:// string.
ms-outlook://compose?to=%#&subject=%#&body=%#
iOS is pretty strict with app sandboxes, you cannot pass local files to other apps unless they are on the same app/file domain (e.g. you're the owner of both apps). There are a few alternatives that work in a watered-down format, but are not relevant for this scenario. Here's the thing, even if you could, Microsoft would need to support this file attachment feature, which it doesn't. Sadly, there's nothing we can do about it on our side... other than asking Microsoft to add the feature.
However, if you want to do this in the apple mail app, that's certainly doable.

Link to iTunes Music in Swift

I like to forward app to iTunes or Apple Music (like done for Instagram or FV) when user clicks a button, below code gives found nil error. Is there a way to do that? Or even better play previews in my app.
var url = NSURL(string: "itms://itunes.apple.com/us/album/ne-olacak-dj-funky-c-vs-ogün-dalka-single/id1202943921")
if UIApplication.shared.canOpenURL(url! as URL) {
UIApplication.shared.openURL(url! as URL)
}
This method expects URLString to contain only characters that are allowed in a properly formed URL. All other characters must be properly percent escaped. Any percent-escaped characters are interpreted using UTF-8 encoding.
and you need to encode it before passing it to NSURL, you can do this via stringByAddingPercentEncodingWithAllowedCharacters
let url = URL(string: "itms://itunes.apple.com/us/album/ne-olacak-dj-funky-c-vs-ogün-dalka-single/id1202943921".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!)
if UIApplication.shared.canOpenURL(url! as URL) {
UIApplication.shared.open(url!, options: [:], completionHandler: nil)
}
for that error you need to follow this
This is a new enforced security measure that apple has implemented on any app that is build in iOS 9.
The only solution so far is to add an entry in the info.plist file with the Key LSApplicationQueriesSchemes and add "itms" and any other url scheme that your app will be linking to in this array.

swift 2.0 UIWebview displays white page only

I write this code:
#IBOutlet weak var webView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
let url = NSURL (string: "http://google.com");
let requestObj = NSURLRequest(URL: url!);
webView.loadRequest(requestObj);
self.view.addSubview(webView)
}
run the code, iPhone simulator display white page only but no warning error
and I change the code to:
let url = NSURL (string: "http://apple.com");
just change google to apple, then it works - simulator displayed apple site
So I put the other site url but it's same like first one, only it displays apple.com
I don't know what is wrong about this code please help me! thank you :)
You should get the error:
App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.
Find Info as the image below shows and do the steps:
1.On the last line add the +
2.Enter the name of the group: App Transport Security
3.Right click on the group and select Add Row
4.Enter Allow Arbitrary Loads
5.Set the value on the right to YES
no need this line if you have connect it from storyboard
self.view.addSubview(webView)
App Transport Security has prevented your web view from loading the page over http. You can either disable it, per William Hu's answer, or switch over to using https links (which is the recommended option).

LinkedIn open url company in iOS (URL Scheme)

I need to open in the LinkedIn app a company url from my iOS app in Swift. I have tried to do that with URL Scheme, but I haven't achieved it.
This code open the LinkedIn app, but not in the url I need:
UIApplication.sharedApplication().openURL(NSURL(string: "linkedin://profile/xxx_id_company_xxx")!)
Can anyone help me?
Swift 4
In your info.plist under LSApplicationQueriesSchemes add
<string>linkedin</string>, then in your code just add
let webURL = URL(string: "https://www.linkedin.com/in/yourName-yourLastName-yourID/")!
let appURL = URL(string: "linkedin://profile/yourName-yourLastName-yourID")!
if UIApplication.shared.canOpenURL(appURL) {
UIApplication.shared.open(appURL, options: [:], completionHandler: nil)
} else {
UIApplication.shared.open(webURL, options: [:], completionHandler: nil)
}
It seems the correct format is "linkedin://companyName/companyId"
See this SO question: How can open LinkedIn Comapny Url in iPhone app programmatically?
This linkedin company url scheme is working for me
linkedin://company?id={company-id}
This objective c code trys to open linkedin company page in linkedin app and fall backs to a modal webview presenting company web page.
/* try to open linkedin app with company url */
if (![[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"linkedin://company?id=2589010"]]) {
/* Unable to open linked app, present web page with url #"https://www.linkedin.com/company/sesli-sozluk" */
...
}
You can find your "company id" in the source code of your company page on linkedin. Search for "company-id" or "companyId", it is in a hidden input field.

Resources