1. 程式人生 > >iOS中[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@""]]的使用

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

使用系統自帶功能,傳送簡訊、撥打電話、傳送郵件、開啟網站

// 呼叫自帶mail
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://[email protected]"]];
// 呼叫電話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:[email protected]";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];

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];

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/[email protected]";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];

NSString *stringURL = @"irc://irc.example.domain/[email protected]";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];


相關推薦

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

使用系統自帶功能,傳送簡訊、撥打電話、傳送郵件、開啟網站 // 呼叫自帶mail [[UIApplication sharedApplication] openURL:[NSURL URLWithSt

iOS開發使用[[UIApplication sharedApplication] openURL:]載入其它應用

轉載自:http://blog.csdn.net/hengshujiyi/article/details/21172127 在iOS開發中,經常需要呼叫其它App,如撥打電話、傳送郵件等。UIApplication:openURL:方法是實現這一目的的最簡單方法,該方法

iOS [UIApplication sharedApplication] openURL等常用的方法使用例如:打電話、定位等

1、打電話 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://電話號碼"]]; 2、發簡訊 [[UIApplication sharedApplication] openURL

UIApplication.sharedApplication().openURL的使用(Swift版)

UIApplication.sharedApplication().openURL(NSURL(string: "http://www.163.com")!) //瀏覽器開啟 UIApplic

IOSUIApplication sharedApplication詳細解釋

iPhone應用程式是由主函式main啟動,它負責呼叫UIApplicationMain函式,該函式的形式如下所示: int UIApplicationMain ( int argc, char *argv[], NSString *princi

ios-NSURL URLWithString:relativeToURL的坑

先說前提 某個具體介面的路徑是 “/user/getInfo”, NSURL *baseURL = [NSURL URLWithString:@"https://api.mydomain.com/api"]; NSURL *relativeURL = [NSURL

ios-設定狀態列樣式 [UIApplication sharedApplication].statusBarStyle

在info.plist檔案中新增一個屬性View controller-based status bar appearance,設定為No(不支援在檔案中設定狀態列樣式) 然後在AppDelegate中寫上[UIApplication sharedApplication].status

UIApplication sharedApplication詳細解釋-IOS

iPhone應用程式是由主函式main啟動,它負責呼叫UIApplicationMain函式,該函式的形式如下所示:  int UIApplicationMain (  int argc,  char *argv[],  NSString *principalClassName,  NSString *de

iOSUDP的使用

ios receive str add rec void enc array 區分 // // ViewController.m // UDPDemo // // Created by qianfeng01 on 15-8-13. // Copyright (c

IOS公布應用程序,進度條一直不走怎麽處理

sso pan arch 技術分享 成功 csdn 版本 進度條 div 在IOS中公布應用程序非常是喜聞樂見。近期1周。我更新了6次版本號。可是時不時的會卡住,進度條不走。最後總結了幾個原因。 1.在公布前你要確認自己的證書是否配置正確 2.DNS域名server有沒

小胖說事28------iOSextern,static和const差別和使用方法

方法 string 文件 only 聲明 sans nbsp ring const 通俗的講: extern字段使用的時候,聲明的變量為全局變量,都能夠調用,也有這樣一種比較狹義的說法:extern能夠擴展一個類中的變量到還有一個類中;

iOS.pch文件怎樣使用

water csdn 例如 popu p s 老版本 tex content data- pch 能夠用來存儲共享信息,比方設備屏幕的寬度,高度。版本等等 公用信息 Xcode 老版本號會自己主動為我們創建pch文件,新版本號開始不自己主動創建了。假設須要使用能夠自己手

從deque到std::stack,std::queue,再到iOS NSArray(CFArray)

blog image nis get 容器 view 緩沖 div n-1 從deque到std::stack,std::queue,再到iOS 中NSArray(CFArray) deque deque雙端隊列,分段連續空間數據結構,由中控的map(與其說map,不

iOS 刪除cookie的正確做法

nbsp -h ring html tpc bold normal dom http 需求:刪除 qq 登錄的 cookie,保證下次打開 qq 登錄頁面不會默認登錄 實現: NSString *url =@"https://w.mail.qq.com

iOS 最新支付寶支付(AliPay) 韓俊強的博客

urlencode init 易用 微軟雅黑 per 回調 process class lis 每日更新關註:http://weibo.com/hanjunqiang 新浪微博 如今的支付方式一般有三種, 支付寶, 微信, 網銀. 個人認為最簡單易用的還是支付寶

RunTime運行時在iOS的應用之UITextField占位符placeholder

指向 field 失去 程序 拷貝 ace 底層 文本 ram RunTime運行時機制 runtime是一套比較底層的純C語言API, 屬於1個C語言庫, 包含了很多底層的C語言API。 在我們平時編寫的OC代碼中, 程序運行過程時, 其實最終都是轉成了runtime的C

淺談iOS的RunLoop

一段 ping itl rst 使用 http ram art 分享 首先解釋下為什麽是淺談,主要是RunLoop這個東西不單單是iOS的範疇,還涉及到操作系統,我指的淺談僅僅針對ios上層應用,底層的東西概不涉及 ,所以只能淺談淺談了。 在淺談RunLoop之前我們來寫個

iOSxib與storyboard原理,與Android界面布局的異同

ast int mvc color ron rect sdn -m control 用文本標記語言來進行布局,用的最多的應該是HTML語言。HTML能夠理解為有一組特殊標記的XML語言。 一、iOS中xib與storyboard顯示原理 在iOS中基

iOS 使用 iconfont

load pos sta 矢量圖 方法 如何 class 制圖 之間 如何使用自定義字體 在講icon font之前,首先先來看看普通自定義字體是如何在ios中使用的,兩個原理是一樣的。這裏以KaushanScript-Regular為例: Step 1:

iOS數組遍歷的方法及比較

結果 keyword div standard c語言 tracking dsm track 代碼 數組遍歷是編碼中很常見的一種需求,我們來扒一拔iOS裏面都有什麽樣的方法來實現,有什麽特點。 因為ios是兼容C語言的,所以c語言裏面的最最常見的for循環遍