通過openURL的方式啟動其它App

來源:互聯網
上載者:User

標籤:style   class   blog   code   http   color   

假設有兩個App,項目名分別是SampleA和SampleB,需要在SampleA裡點擊一個Button來啟動SampleB,並傳遞一個字串。具體實現步驟如下:

1. 在SampleB的info.plist檔案裡新增一個URL Schemes,並指定一個字串,這個字串就是調用App的連結名稱:

 

2. 在SampleA的按鈕點擊操作裡執行下面代碼:

- (IBAction)openClickHandler:(id)sender{    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"myapp23://time_is_money"]];}

 

3. 在SampleB的AppDelegate類裡,調用系統事件處理傳遞過來的URL:

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{    NSString *strInfo = [[url host] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:strInfo delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];    [alertView show];        return YES;}

 

總結:

1. 通過openURL的方式啟動其它App時,地址格式為 @“URL Scheme://URL identifier”,其中URL identifier是可選的。

2. URL identifier不能含有空格和問號。

3. apple並不支援這種做法,實際產品開發中慎用。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.