Skip to content

Instantly share code, notes, and snippets.

@dotWasim
Last active February 20, 2020 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dotWasim/4d5bc8bd3f1df2c0c3241cb11d864029 to your computer and use it in GitHub Desktop.
Save dotWasim/4d5bc8bd3f1df2c0c3241cb11d864029 to your computer and use it in GitHub Desktop.
decode a url
//
// ViewController.swift
// Test
//
// Created by Wasim Alatrash on 1/28/20.
// Copyright © 2020 Wasim Alatrash. All rights reserved.
//
import UIKit
import SafariServices
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func viewDidAppear(_ animated: Bool) {
let url = "http://example.com/6f19bb7f-692c-ea11-bb54-000d3a609328/18/الألوان 1 2.docx"
showAttachment(url: url, name: "test")
}
func showAttachment(url: String?, name: String){
if let urlString = url,
let url = URL(decode: urlString){
let vc = SFSafariViewController(url: url)
vc.title = name
vc.modalPresentationStyle = .fullScreen
present(vc, animated: true, completion: nil)
}
}
}
extension URL {
init?(decode string: String) {
guard let decoded = string.addingPercentEncoding(withAllowedCharacters: .urlFragmentAllowed) else { return nil }
self.init(string: decoded)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment