Created
March 19, 2018 13:17
-
-
Save NeilsUltimateLab/19f79daad3842dd255210e1ace8ab657 to your computer and use it in GitHub Desktop.
Open iOS system apps.
This file contains hidden or 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
// | |
// SystemAppType.swift | |
// REIWA | |
// | |
// Created by Neil Jain on 19/03/18. | |
// Copyright © 2018 NeilsUltimateLab. All rights reserved. | |
// | |
import Foundation | |
enum SystemAppType { | |
/// **Example** : | |
/// | |
/// tel:1-408-555-5555 | |
/// | |
/// **Reference**: https://developer.apple.com/library/content/featuredarticles/iPhoneURLScheme_Reference/PhoneLinks/PhoneLinks.html#//apple_ref/doc/uid/TP40007899-CH6-SW1 | |
case telephone(String) | |
/// **Example**: | |
/// | |
/// facetime:[email protected] | |
/// facetime://[email protected] | |
/// **Reference**: https://developer.apple.com/library/content/featuredarticles/iPhoneURLScheme_Reference/FacetimeLinks/FacetimeLinks.html#//apple_ref/doc/uid/TP40007899-CH2-SW1 | |
case facetime(String) | |
/// **Example**: | |
/// | |
/// facetime-audio:[email protected] | |
/// facetime-audio://[email protected] | |
/// **Reference**: https://developer.apple.com/library/content/featuredarticles/iPhoneURLScheme_Reference/FacetimeLinks/FacetimeLinks.html#//apple_ref/doc/uid/TP40007899-CH2-SW1 | |
case facetimeAudio(String) | |
/// **Example**: | |
/// | |
/// sms:1-408-555-1212 | |
/// **Reference**: https://developer.apple.com/library/content/featuredarticles/iPhoneURLScheme_Reference/SMSLinks/SMSLinks.html#//apple_ref/doc/uid/TP40007899-CH7-SW1 | |
case sms(String) | |
/// **Example** : | |
/// | |
/// mailto:[email protected] | |
/// | |
/// **Reference** : https://developer.apple.com/library/content/featuredarticles/iPhoneURLScheme_Reference/MailLinks/MailLinks.html#//apple_ref/doc/uid/TP40007899-CH4-SW1 | |
case mail(String) | |
case url(String?) | |
} | |
extension SystemAppType { | |
var url: URL? { | |
switch self { | |
case .telephone(let telNumber): | |
return URL(string: "tel://\(telNumber)") | |
case .facetime(let fId): | |
return URL(string: "facetime://\(fId)") | |
case .facetimeAudio(let fId): | |
return URL(string: "facetime-audio://\(fId)") | |
case .sms(let number): | |
return URL(string: "sms://\(number)") | |
case .mail(let email): | |
return URL(string: "mailto:\(email)") | |
case .url(let str): | |
guard let urlString = str else { return nil } | |
return URL(string: urlString) | |
} | |
} | |
} | |
extension UIApplication { | |
func open(_ systemApp: SystemAppType) { | |
guard let url = systemApp.url else { | |
return | |
} | |
if canOpenURL(url) { | |
openURL(url) | |
} else { | |
print("Application can not open app: \(systemApp)") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment