Last active
February 20, 2020 12:19
-
-
Save dotWasim/4d5bc8bd3f1df2c0c3241cb11d864029 to your computer and use it in GitHub Desktop.
decode a url
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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