How IOS calls other applications

Source: Internet
Author: User
Tags rfc home screen reverse dns

1. Call System Applications

1. Calling the App Store Interface Method in actual development, we often need to recommend other applications and recommend our own paid software, so we need to directly connect to the corresponding page of the app store in the program. The actual method is very simple. The Openurl method of the uiapplication class is used: [[uiapplication sharedapplication] Openurl: [nsurl urlwithstring: @ "connection of the program"]; 1. Call other application method 1) Call the built-in mail handler [[uiapplicationsharedapplication] Openurl: [nsurlurlwithstring: @ "mailto: // admin@hzlzh.com"]; 2) call phone comment [[uiapplication sharedapplication] Openurl: [nsurlurlwithstring: @ "Tel: // 8008808888"]; Comment 3) Call SMS comment [[uiapplicationsharedapplication] Openurl: [nsurl urlwithstring: @ "SMS: // 800888"]; then 4) Call the browser safari plugin [[uiapplicationsharedapplication] Openurl: [nsurlurlwithstring: @ "http://www.hzlzh.com"]; 5) Call remote applications [[uiapplicationsharedapplication] Openurl: [nsurl urlwithstring: @ "remote: // fff"];


2. Call the self-developed application 1) in the plist file, register the external interface in xcode Group & files, expand resources, and select <app> info. plist right-click information property list, select URL types from the list, and right-click Add row to add an object (item) right-click "item add row", select "url schemes" from the list, right-click "add an object" (Item1), and set "Item1" to "MyApp", which is an external interface. Other applications can use this interface, call the application plist, as shown in figure 2) Add the following code to the application where you need to call the external interface registered above: nsurl * url = [nsurl urlwithstring: @ "MyApp:"]; [[uiapplication sharedapplication] Openurl: url ]; Step 1: You can enable the user to open your other applications in your application. If you add a parameter, you 'd better write it as @ "MyApp ://......... ", it is like replacing" HTTP "with" MyApp "in an HTTP request ". 3) process the URL request application delegate to process the URL request passed to the application in application: handleopenurl: method. If you have registered a custom URL mode for your application, you must implement this method in the delegate. The protocol used by the URL Based on the custom mode is understandable to the application requesting the service. The URL contains the desired information of the registration mode application, which is required by the program to process or respond to the URL request. The nsurl object passed to application: handleopenurl: The method represents the URL in the cocoa touch framework. The nsurl follows the RFC 1808 standard and contains some methods to return the URL elements defined in RFC 1808, including the user name, password, request, segment, and parameter string. The "protocol" corresponding to your registered custom mode can use these URL elements to transmit various information. In the Application: handleopenurl: method implementation shown in 1-2 of the program list, the imported URL object carries information about the specific application in its request and fragment. The application delegate extracts this information-in this example, it refers to the name and expiration date of a to-do task-and creates model objects for the application based on this information. [Plain]
-(Bool) Application :( uiapplication *) Application handleopenurl :( nsurl *) URL {If ([[URL Scheme] isequaltostring: @ "MyApp"]) {// processing link return yes;} return no;}-(bool) Application :( uiapplication *) Application handleopenurl :( nsurl *) URL {If ([URL Scheme] isw.tostring: @ "MyApp"]) {// process link return yes;} return no;} verify the input URL. For more information about how to avoid URL Processing problems, see the verification input section in the security coding guide. If you want to know the URL mode defined by Apple, refer to Apple's URL mode and refer to the second method for processing URL requests [CPP]
-(Bool) Application :( uiapplication *) Application didfinishlaunchingwitexceptions :( nsdictionary *) launchoptions {// nsurl * url = [launchoptions objectforkey: uiapplicationlaunchoptionsurlkey]; If (URL) {// determine if ([[URL Scheme] isw.tostring: @ "MyApp"]) {// process link} self. window = [[[uiwindow alloc] initwithframe: [uiscreen mainscreen] bounds] autorelease]; // override point for customizatio N after application launch. self. viewcontroller = [[[viewcontroller alloc] initwithnibname: @ "viewcontroller" Bundle: Nil] autorelease]; self. window. rootviewcontroller = self. viewcontroller; [self. window makekeyandvisible]; return yes;}-(bool) Application :( uiapplication *) Application didfinishlaunchingwitexceptions :( nsdictionary *) launchoptions {// nsurl * url = [launchoptions objectforkey: UIA Pplicationlaunchoptionsurlkey]; If (URL) {// make the corresponding judgment if ([[URL Scheme] isequaltostring: @ "MyApp"]) {// process link} self. window = [[[uiwindow alloc] initwithframe: [[uiscreen mainscreen] bounds] autorelease]; // override point for customization after application launch. self. viewcontroller = [[[viewcontroller alloc] initwithnibname: @ "viewcontroller" Bundle: Nil] autorelease]; self. window. rootviewcontrolle R = self. viewcontroller; [self. window makekeyandvisible]; return yes;} Note: Application: didfinishlaunchingwitexceptions: Is always called when the IOS program starts. The second parameter launchoptions is an object of the nsdictionary type, the reason why the program is started is stored in it. For possible key values in launchoptions, see the launch options keys section of the uiapplication class reference. If the user starts the instance directly, there is no data in lauchoptions. If other applications use Openurl: To start the instance, the object corresponding to uiapplicationlaunchoptionsurlkey is the nsurl ), uiapplicationlaunchoptionssourceapplicationkey corresponds to the bundle ID (nsstring) of the started source application. If it is started by a local notification, uiapplicationlaunchoptionslocalnotificationkey corresponds to the local notification object (uilocalnotification) for the application to be started ); if a remote notification is enabled, the uiapplicationlaunchoptionsremotenotificationkey corresponds to the remote notification userinfo (nsdictionary) of the application to be started. Other keys include uiapplicationlaunchopt. Ionsannotationkey, uiapplicationlaunchoptionslocationkey, and uiapplicationlaunchoptionsnewsstanddownloadskey. Reference: http://blog.csdn.net/tiger119/article/details/7949004 4). Quick test external call 1. Back to home screen, start Safari (on the iPhone simulator, choose hardware-> Home command on the menu to go back to home screen ). 2. in the address bar of safari, type a URL in the Custom mode, that is, "MyApp:". If you add a parameter, the URL is "MyApp ://........ "3. check whether your application is started and whether the application delegate receives the application: handleopenurl: Message. 3. Official principles and communication with other applications if an application supports some known types of URLs, you can communicate with the program through the corresponding URL mode. However, in most cases, URLs are only used to simply start an application and display information related to the caller. For example, for an application used to manage address information, you can include an address that the maps program can process in the URL sent to it to display the corresponding location. This level of communication creates a highly integrated environment for users, reducing the necessity for applications to re-implement the functions already implemented by other programs on the device. Apple's built-in support for HTTP, mailto, tel, and sms url modes, as well as HTTP-based URLs that point to maps, YouTube, and iPod programs. Applications can also register custom URL modes. Your application can communicate with other applications by creating an nsurl object in the correct format and passing it to the Openurl: Method of the shared uiapplication object. Openurl: The method starts an application registered to receive the URL type and sends the URL to it. When a user finally exits the application, the system usually restarts your application, but not always. The system will consider the user's actions in the URL Processing Program and whether it is reasonable for the user to return your application, and then make a decision. The following code snippet shows how a program requests services provided by another program (assuming that "todolist" in this example is a custom mode registered by the Application ): nsurl * myurl = [nsurl urlwithstring: @ "todolist: // www.acme.com? Quarterly % 20 Report #200806231300 "]; [[uiapplication sharedapplication] Openurl: myurl]; Note: If your url type contains the same pattern as that defined by Apple, the program provided by Apple is started, not your program. If there are multiple third-party applications registered to process the same URL mode, it is not important to indicate which program will process this type of URL: if your url type contains the same pattern as that defined by Apple, it starts the program provided by Apple, not your program. If there are multiple third-party applications registered to process the same URL mode, the type of URL is not defined by which program. If your application defines your own URL mode, you should implement the method for processing this mode. The specific information is described in the "implement custom URL mode" section. For URL Processing supported by the system, including how to process the URL format, see the URL mode reference of apple. You can register a URL type that contains the custom mode for your application. The custom URL mode allows third-party applications to interact with other programs and systems. Through the custom URL mode, the application can provide its own services to other programs. When registering a custom URL mode for your application, you must specify the sub-attribute of the cfbundleurltypes attribute when registering the URL type. We have already introduced this attribute in the "information property list" section. The cfbundleurltypes attribute is a dictionary array in the info. plist file of the application. Each Dictionary defines the URL types supported by the application. Table 1-6 describes the keys and values of the cfbundleurltypes dictionary. Table 1-6 key and value of the cfbundleurltypes attribute cfbundleurlname is a string that represents the abstract name of the URL type. To ensure its uniqueness, we recommend that you use reverse DNS-style identifiers, such as com. Acme. myscheme. The URL type name provided here is a key pointing to a localized string, which is located in the infoplist. Strings file in the subdirectory of the localized Language Pack. A localized string is a recognizable URL type name in a language. Cfbundleurlschemes: an array of URL patterns, indicating the URL type. Each mode is a string. URLs of the specified URL type all carry their pattern components. Figure 1-7 shows the info. plist file being edited using the built-in xcode editor. In this figure, the URL type entry in the left column is equivalent to the cfbundleurltypes key that you directly add to the info. plist file. Similarly, the URL identifier and URL schemes entries are equivalent to the cfbundleurlname and cfbundleurlschemes keys. In info. in the plist file, define a custom URL mode. After you define the cfbundleurltypes attribute and register the URL type with the custom mode, you can perform the test in the following way: concatenate, install, and run your applications. Go back to the home screen and start Safari (on the iPhone simulator, select hardware> Home on the menu to return to the home screen ). In the address bar of safari, type a URL in the Custom mode. Check whether your application is started and whether the application delegate receives the application: handleopenurl: Message.

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.