IOS checks whether an application exists and starts

Source: Internet
Author: User

Background: if there are two programs a and B (of course you have to write them on your own) and you want to judge whether program B exists on the local machine in program a, start it, A dialog box is displayed at startup. The content of the dialog box is included in program. The background ends. The following is the implementation process.

Implementation:

1. open info in program B. in the plist file, create a key = URL types, create a URL schemes under this file, and set the value after item0 to "MyApp". The MyApp here is random, what do you like. In this way, other programs can use this MyApp to call this program.

2. In the "appdelegate. m" file of program B, assume the following method.

-(Bool) Application :( uiapplication *) Application handleopenurl :( nsurl *) URL {// process the passed parameter uialertview * alertview; nsstring * text = [[url host] stringbyreplacingpercentescapesusingencoding: response]; alertview = [[uialertview alloc] initwithtitle: @ "text" message: Text delegate: Nil cancelbuttontitle: @ "OK" otherbuttontitles: Nil]; [alertview show]; [alertview release]; return yes ;}

This method can be understood at a Glance. If you do not understand it, go to the basic tutorial first! I will not explain it too much here.

In this way, program B is ready. Let's witness a magical moment.

3. In program a, execute the following code where you want to call B.

[[Uiapplication sharedapplication] Openurl: [nsurl urlwithstring: @ "MyApp: // Shenyang bin sub-test"];

If the test exists, it can be started normally. If the test does not exist, no error is reported.

4. Now there is no problem with the startup. If you only need to make a single decision, you can change it to another place.

Bool iscunzai = [[uiapplication sharedapplication] canopenurl: [nsurl urlwithstring: @ "MyApp: // Zhiqiang original"]; If (iscunzai) {// exists} else {// does not exist}

Article Source: http://www.cnblogs.com/zhiqiangsimida/archive/2013/01/19/IOS.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.