應用之間調用 UIApplication類的OpenURL方法

來源:互聯網
上載者:User

標籤:

一、UIApplication類的OpenURL方法

1、調用app store介面方法

在實際開發中,往往要推薦自己其他應用和推薦自己的收費軟體,那麼我們就需要在程式中直接連接到app store的相應頁面。

 

實際上的做法很簡單,使用的還是UIApplication類的OpenURL方法: 

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"程式的相應串連"]];

 

2、調用其它應用的方法

// 調用 內建mail

[[UIApplicationsharedApplication] openURL:[NSURLURLWithString:@"mailto://[email protected]"]];

// 調用 電話phone

[[UIApplication sharedApplication] openURL:[NSURLURLWithString:@"tel://8008808888"]];

 

// 調用 SMS

[[UIApplicationsharedApplication] openURL:[NSURL URLWithString:@"sms://800888"]];

// 調用內建 瀏覽器 safari

[[UIApplicationsharedApplication] openURL:[NSURLURLWithString:@"http://www.hzlzh.com"]];

 

// 調用 Remote

[[UIApplicationsharedApplication] openURL:[NSURL URLWithString:@"remote://fff"]];

調用phone可以傳遞號碼,調用SMS只能設定號碼,不能初始化SMS內容。

 

二、應用程式間通訊

 

1、調在plist檔案中,註冊對外介面

找到appname-info.plist檔案,點擊開啟它,在列表中找到URL types(如果沒有,可添加一個URL types )裡面的內容設定看:

 

 

關鍵Key和Value是 URL identifier => com.zilanxing.andpush;URL Schemes => andpush

到此對外介面登入好

2、調用上面的介面通訊

註冊url地址:andpush://cn.andpush.com/access/register?code=zOdSpC8ZXv

// 通過iOS瀏覽器開啟應用程式註冊應用

 

// andpush使用者註冊,當使用者郵箱收到邀請連結,直接點擊下面連結就可以開啟andpush應用程式的註冊頁面

<a href="andpush://cn.andpush.com/access/register?code=zOdSpC8ZXv">andpush://cn.andpush.com/access/register?code=zOdSpC8ZXv</a>

// 通過其它App應用開啟andpush應用程式的註冊頁面

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"andpush://cn.andpush.com/access/register?code=zOdSpC8ZXv"]];

3、 andpush 響就註冊頁面的請求

在AndPush應用的AppDelegate.m檔案中添加如下代碼:

 

 

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url

{

    if (!url) {

        return NO;

    }

    NSLog(@"handleOpenURL: %@", [url absoluteString]);

    // 在host等於cn.andpush.com時,說明是註冊請求

    if ([[url host] isEqualToString:@"cn.andpush.com"]) {

        // 請求的url地址: andpush://cn.andpush.com/access/register?code=zOdSpC8ZXv

        // 擷取註冊邀請碼 code

        NSString *code = [[url query] substringFromIndex:[[url query] rangeOfString:@"code="].location+5];

        NSLog(@"code: %@", code);

        // 使用本地 ViewController 來註冊

        UserRegisterViewController *viewController = [[[UserRegisterViewControlleralloc] init] autorelease];

        viewController.title = @"註冊";

        viewController.code = code;

        //從底部顯示視圖

        UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];

        navigationController.title = @"註冊";

        [self.tabBarController presentModalViewController:navigationController animated:TRUE];

        [navigationController release];

        // [self.navigationController pushViewController:controller animated:YES];

        // [controller release];

        return YES;

    } else {

        return NO;

    }

}

到此搞定,以後再完善。

 

其它參考:

http://www.cocoachina.com/newbie/tutorial/2012/0529/4302.html

http://www.byywee.com/page/M0/S753/753470.html

http://www.cocoachina.com/bbs/simple/?t58388.html

轉自http://blog.163.com/wzi_xiang/blog/static/659829612012910103458775/ 

應用之間調用 UIApplication類的OpenURL方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.