IOS用openurl打開設置選項 ==…

在代碼中調用如下代碼:

NSURL*url=[NSURLURLWithString:@"prefs:root=NOTIFICATIONS_ID"];
[[UIApplication sharedApplication] openURL:url];
即可跳轉到設置頁面的對應項。

About — prefs:root=General&path=About
Accessibility — prefs:root=General&path=ACCESSIBILITY
Airplane Mode On — prefs:root=AIRPLANE_MODE
Auto-Lock — prefs:root=General&path=AUTOLOCK
Brightness — prefs:root=Brightness
Bluetooth — prefs:root=General&path=Bluetooth
Date & Time — prefs:root=General&path=DATE_AND_TIME
FaceTime — prefs:root=FACETIME
General — prefs:root=General
Keyboard — prefs:root=General&path=Keyboard
iCloud — prefs:root=CASTLE
iCloud Storage & Backup —prefs:root=CASTLE&path=STORAGE_AND_BACKUP
International — prefs:root=General&path=INTERNATIONAL
Location Services — prefs:root=LOCATION_SERVICES
Music — prefs:root=MUSIC
Music Equalizer — prefs:root=MUSIC&path=EQ
Music Volume Limit — prefs:root=MUSIC&path=VolumeLimit
Network — prefs:root=General&path=Network
Nike + iPod — prefs:root=NIKE_PLUS_IPOD
Notes — prefs:root=NOTES
Notification — prefs:root=NOTIFICATIONS_ID
Phone — prefs:root=Phone
Photos — prefs:root=Photos
Profile —prefs:root=General&path=ManagedConfigurationList
Reset — prefs:root=General&path=Reset
Safari — prefs:root=Safari
Siri — prefs:root=General&path=Assistant
Sounds — prefs:root=Sounds
Software Update —prefs:root=General&path=SOFTWARE_UPDATE_LINK
Store — prefs:root=STORE
Twitter — prefs:root=TWITTER
Usage — prefs:root=General&path=USAGE
VPN — prefs:root=General&path=Network/VPN
Wallpaper — prefs:root=Wallpaper
Wi-Fi — prefs:root=WIFI


demo:

Safari

AnyURL starting with http:// which does not point to maps.google.comor www.youtube.com is sent to Safari:

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

Apparently feed://opens http://reader.mac.com inSafari.

Maps

URLs starting with http://maps.google.com openup the "Maps" application automatically:

NSString *title = @"title";
float latitude = 35.4634;
float longitude = 9.43425;
int zoom = 13;
NSString *stringURL = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@@%1.6f,%1.6f&z=%d", title, latitude, longitude, zoom];
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];

It seems that maps:// also opens up the Mapsapplication.

Phone

Thephone links start with "tel:" but must not contain spaces orbrackets (it can contain dashes and "+" signs, though):

NSMutableString *phone = [[@"+ 12 34 567 89 01" mutableCopy] autorelease];
[phone replaceOccurrencesOfString:@" " 
                       withString:@"" 
                          options:NSLiteralSearch 
                            range:NSMakeRange(0, [phone length])];
[phone replaceOccurrencesOfString:@"(" 
                       withString:@"" 
                          options:NSLiteralSearch 
                            range:NSMakeRange(0, [phone length])];
[phone replaceOccurrencesOfString:@")" 
                       withString:@"" 
                          options:NSLiteralSearch 
                            range:NSMakeRange(0, [phone length])];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", phone]];
[[UIApplication sharedApplication] openURL:url];

SMS

Toopen the SMS application, just use the sms: protocol in yourURL:

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

Youcan specify a phone number, but apparently not a default text foryour message:

NSString *stringURL = @"sms:+12345678901";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];

Thesame restrictions apply as for phone URLs, regarding spaces,brackets and dashes.

Mail

These URLs launch Mail and open the compose message controller:

NSString *stringURL = @"mailto:[email protected]";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];

Youcan also provide more information, for a customized subject andbody texts:

NSString *subject = @"Message subject";
NSString *body = @"Message body";
NSString *address = @"[email protected]";
NSString *cc = @"[email protected]";
NSString *path = [NSString stringWithFormat:@"mailto:%@?cc=%@&subject=%@&body=%@", address, cc, subject, body];
NSURL *url = [NSURL URLWithString:[path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:url];

Youmight also omit some information:

NSString *subject = @"Message subject";
NSString *path = [NSString stringWithFormat:@"mailto:?subject=%@", subject];
NSURL *url = [NSURL URLWithString:[path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:url];

Formore complex body texts, you might want to use theCFURLCreateStringByAddingPercentEscapes() function, as explainedabove in this page.

YouTube

URLs starting with http://www.youtube.com openup the "YouTube" application automatically:

NSString *stringURL = @"http://www.youtube.com/watch?v=WZH30T99MaM";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];

Italso works with this URL (which normally brings the Flash videoplayer used by YouTube):

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

iTunes

Toopen up iTunes, use this URL:

NSString *stringURL = @"http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewAlbum?i=156093464&id=156093462&s=143441";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];

AppStore

Very similar to the iTunes URLs:

NSString *stringURL = @"http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=294409923&mt=8";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];

iBooks

(source: http://akos.ma/aqdr)

NSString *stringURL = @"itms-books:";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
NSString *stringURL = @"itms-bookss:";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];

Third Party Applications

Most URL schemes in this list come from AppLookup.

AirSharing

Launch the application:

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

Alocola

Launch the application:

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

AppigoNotebook

Launch the application:

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

AppigoTodo

Launch the application:

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

Create a new task:

NSString *template = @"appigotodo://com.example.xyzapp/import?name=%@&note=%@&due-date=%@&priority=%@&repeat=%@";
NSString *name = @"Buy some milk";
NSString *note = @"Stop on the way home from work.";
NSString *dueDate = @"2009-07-16";
NSString *priority = @"1";
NSString *repeat = @"101";
NSString *stringURL = [NSString stringWithFormat:template, name, note, dueDate, priority, repeat];
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];

Duo

Launch the application and pre-populate the update field with yourdesired Tweet/Facebook update. Optional: Provide Duo with thecustom URL and return path to your app to provide the user with abutton to return to your app.

NSString *appID = @"Your Apps Name";
NSString *updateInfo = @"The Tweet/Status Update";
NSString *returnScheme = @"Your Apps Return URL Scheme";
NSString *returnPath = @"Your/Apps/Return/Path";
NSString *baseURL = @"duoxx://updateFaceTwit?";
        
NSString *encodedUpdateInfo = [updateInfo stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSString *urlString = [NSString stringWithFormat:@"%@BLappID=%@;BLupdateInfo=%@;BLreturnScheme=%@;BLreturnPath=%@", 
                                                   baseURL, appID, encodedUpdateInfo, returnScheme, returnPath];

NSURL *url = [NSURL URLWithString:urlString];
[[UIApplication sharedApplication] openURL:url];

 

TheCartographer

Launch app and add a placemark at given coordinate:

NSString *title = @"Placemark title (optional)";
NSString *summary = @"Placemark description (optional)";
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(123.0, 12.0);

title = [(id)CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)title, NULL, (CFStringRef)@";/?:@&=+$,", kCFStringEncodingUTF8) autorelease];
summary = [(id)CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)summary, NULL, (CFStringRef)@";/?:@&=+$,", kCFStringEncodingUTF8) autorelease];

NSString *cartographerURL = [NSString stringWithFormat:@"cartographer://placemark?coordinate=%lf,%lf&title=%@&summary=%@", 
         coordinate.latitude, coordinate.longitude, title, summary];

NSURL *url = [NSURL URLWithString:cartographerURL];
[[UIApplication sharedApplication] openURL:url];

Launch app and load either a KML source or a Google My Map:

NSString *sourceURL = @"http://....";
// e.g. http://maps.google.com/maps/ms?ie=UTF8&hl=en&msa=0&msid=208320711678395936256.00046bbcfdcd1f3ebf64b&z=5

// Optional:
MKCoordinateRegion region = ...;
sourceURL = [sourceURL stringByAppendingFormat:@"&ll=%lf,%lf&spn=%lf,%lf", 
               region.center.latitude, region.center.longitude, region.span.latitudeDelta, region.span.longitudeDelta];

NSURL *url = [NSURL URLWithString:[sourceURL stringByReplacingOccurrencesOfString:@"http://" withString:@"cartographer://"]];
[[UIApplication sharedApplication] openURL:url];

 

ChatCo

NSString *stringURL = @"irc://irc.example.domain/roomName";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
NSString *stringURL = @"irc://irc.example.domain/Nickname@roomName";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
NSString *stringURL = @"irc://irc.example.domain/Nickname!Realname@roomName";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章