Zoeken…


Syntaxis

  1. // canOpenURL methode verifieert of er een app is die het aangegeven URL-schema aankan.

  2. // Snel

    UIApplication.sharedApplication (). CanOpenURL (_ aUrl: NSURL)

  3. // Doelstelling C

    [[UIApplication sharedApplication] canOpenURL: (NSURL *) aUrl];

  4. // openURL- methode probeert een bron te openen die zich op URL bevindt. JA / waar als het anders is geopend NEE / onwaar.

  5. // Snel

    UIApplication.sharedApplication (). OpenURL (_ aUrl: NSURL)

  6. // Doelstelling C

    [[UIApplication sharedApplication] openURL: (NSURL *) aUrl];

parameters

Parameter Betekenis
AURL een NSURL-instantie waarin een ingebouwde of aangepaste schematekenreeks wordt opgeslagen

Opmerkingen

In iOS9 en hoger moet uw app alle URL-schema's vermelden die u wilt doorzoeken. Dit wordt gedaan door LSApplicationQueriesSchemes te voegen aan Info.plist


iOS heeft ingebouwde ondersteuning voor de tel , http / https , sms , mailto , facetime schema's. Het ondersteunt ook op http gebaseerde URL's voor Youtube , Maps en iTunes apps.

Voorbeelden van ingebouwde URL-schema's:

tel : tel://123456890 of tel:123456890

http : http://www.google.com

facetime : facetime://azimov@demo.com

mailto : mailto://azimov@demo.com

sms : sms://123456890 of sms:123456890

YouTube : https://www.youtube.com/watch?v=-eCaif2QKfA

Kaarten :

  • Gebruik adres: http://maps.apple.com/?address=1,Infinite+Loop,Cupertino,California

  • Gebruik coördinaten: http://maps.apple.com/?ll=46.683155557,6.683155557

iTunes : https://itunes.apple.com/us/artist/randy-newman/id200900

Opmerking : niet alle speciale tekens worden ondersteund in het tel (bijvoorbeeld * of # ). Dit wordt gedaan vanwege beveiligingsproblemen om te voorkomen dat gebruikers ongeautoriseerde oproepen doorschakelen, dus in dit geval wordt de Phone app niet geopend.

Het ingebouwde URL-schema gebruiken om de Mail-app te openen

Snel:

if let url = URL(string: "mailto://azimov@demo.com") {
    if UIApplication.shared.canOpenURL(url) {
        UIApplication.shared.openURL(url)
    } else {
        print("Cannot open URL")
    }
}

Doelstelling C:

NSURL *url = [NSURL URLWithString:@"mailto://azimov@demo.com"];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
    [[UIApplication sharedApplication] openURL:url];
} else {
    NSLog(@"Cannot open URL");
}

Apple URL-regelingen

Dit zijn URL-schema's die worden ondersteund door native apps op iOS, OS X en watchOS 2 en hoger.

Link openen in Safari:

Doelstelling C

NSString *stringURL = @"http://stackoverflow.com/";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];

Snel:

let stringURL = "http://stackoverflow.com/"
if let url = URL(string: stringURL) {
    UIApplication.shared.openURL(url)
}

Een telefoongesprek beginnen

Doelstelling C

NSString *stringURL = @"tel:1-408-555-5555";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];

Snel:

let stringURL = "tel:1-408-555-5555"
if let url = URL(string: stringURL) {
    UIApplication.shared.openURL(url)
}

HTML

<a href="tel:1-408-555-5555">1-408-555-5555</a>

Een FaceTime-gesprek beginnen

Doelstelling C

NSString *stringURL = @"facetime:14085551234";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];

Snel:

let stringURL = "facetime:14085551234"
if let url = URL(string: stringURL) {
    UIApplication.shared.openURL(url)
}

HTML

<a href="facetime:14085551234">Connect using FaceTime</a>
<a href="facetime:user@example.com">Connect using FaceTime</a>

Berichten-app openen om een sms voor de ontvanger samen te stellen:

Doelstelling C

NSString *stringURL = @"sms:1-408-555-1212";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];

Snel:

let stringURL = "sms:1-408-555-1212"
if let url = URL(string: stringURL) {
    UIApplication.shared.openURL(url)
}

HTML

<a href="sms:">Launch Messages App</a>
<a href="sms:1-408-555-1212">New SMS Message</a>

De Mail-app openen om een e-mail aan de ontvanger te schrijven:

Doelstelling C

NSString *stringURL = @"mailto:foo@example.com";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];

Snel:

let stringURL = "mailto:foo@example.com"
if let url = URL(string: stringURL) {
    UIApplication.shared.openURL(url)
}

HTML

<a href="mailto:frank@wwdcdemo.example.com">John Frank</a>

U kunt ook een onderwerpveld, een bericht en meerdere ontvangers opnemen in de velden Aan, Cc en Bcc. (In iOS wordt het kenmerk van genegeerd.) In het volgende voorbeeld wordt een mailto-URL weergegeven met verschillende kenmerken:

mailto:foo@example.com?cc=bar@example.com&subject=Greetings%20from%20Cupertino!&body=Wish%20you%20were%20here!

Opmerking: het dialoogvenster E-mail opstellen kan ook in de app worden weergegeven met behulp van MFMailComposeViewController .



Modified text is an extract of the original Stack Overflow Documentation
Licentie onder CC BY-SA 3.0
Niet aangesloten bij Stack Overflow