iOS中[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@""]]的使用

使用系统自带功能,发送短信、拨打电话、发送邮件、打开网站

// 调用自带mail
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://admin@163.com"]];
// 调用电话phone
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://8008808888"]]; //退出应用
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"telprompt://8008808888"]];//不退出应用
// 调用 SMS
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://800888888"]];
// 调用自带浏览器 safari
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.baidu.com"]];

// 宏定义使用方法
#define MailSend(email) ([[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"mailto://%@",email]])
#define PhoneCall(phone) ([[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",phone]])
#define PhoneCallAuto(phone) ([[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"telprompt://%@",phone]])
#define SMSSend(phone) ([[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"sms://%@",phone]])
#define SafariOpen(url) ([[UIApplication sharedApplication] openURL:[NSURL URLWithString:url])


查看更多iPhone应用程序的调用和第三方应用程序的调用,可以在iPhoneURL方案查看。

下面列举部分:

Apple iPhone Applications

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

// Maps
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];
// Phone
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
NSString *stringURL = @"sms:"; // 没有电话号码
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];

NSString *stringURL = @"sms:+12345678901"; // 有电话号码
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
// Mail
NSString *stringURL = @"mailto:test@example.com";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];

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

NSString *subject = @"Message subject";
NSString *path = [NSString stringWithFormat:@"mailto:?subject=%@", subject];
NSURL *url = [NSURL URLWithString:[path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:url];
// YouTube
NSString *stringURL = @"http://www.youtube.com/watch?v=WZH30T99MaM";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];

NSString *stringURL = @"http://www.youtube.com/v/WZH30T99MaM";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
// iTunes
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];
// App Store
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];
// AirSharing
NSString *stringURL = @"airsharing://";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
// Alocola
NSString *stringURL = @"alocola://";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
// Appigo Notebook
NSString *stringURL = @"appigonotebook://";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];

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

NSString *template = @"appigotodo://com.example.xyzapp/import?name=%@¬e=%@&due-date=%@&priority=%@&repeat=%@";
NSString *name = @"Buy%20some%20milk";
NSString *note = @"Stop%20on%20the%20way%20home%20from%20work.";
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
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];
// The Cartographer
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];
// 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];


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

番薯大佬

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值