Original: http://blog.sina.com.cn/s/blog_8a6c97b5010162f0.html
Limited and iOS system operating mechanism, in most cases an application will go into the background immediately after entering the suspend or terminate state, that is, cannot execute code, iOS also does not have the concept of similar service in Windows, but there are some exceptions:
1: There are some important tasks, such as saving user data, network download, etc., can apply for a period of time background run time, but the time period of the operation is relatively limited, and there is a time limit, the length of 600 seconds or so.
2: Specific types of applications, including:
- VoIP Applications
- Positioning class Applications
- News applications
- Music class applications
These types of apps can get background running without a time limit. But it's not like you just have to make a statement about the app type, and if trickery, it can't be audited by the App Store. Since in most cases there is only one active application running in the system, plus the high degree of isolation that is caused by the sandbox operation of different applications in iOS, the IPC methods that we are familiar with, such as pipelines, mail slots, shared memory, sockets, and so on, tend to be quite weak, and in this case, Apple also provides the corresponding solution Solution, which we are going to introduce today: the URL schema is simply that the URL schema is the application invocation protocol within iOS, application A can declare a custom invocation protocol, as Http/https, when another application B intends to open app A in the app, it can To open a with a URL that begins with a custom protocol, in addition to the protocol header, additional parameters can be appended to the URL, as described in the following procedure: This is the interaction between Safari and Alocola. Next you'll look at the process of customizing the URL schema. 1: Create Xcode Project 2: Open the project, add the fields as shown in the Info.plist in it: "Lifengzhong" is the custom protocol name I registered for this app, other apps if you want to call my app, just open the shape: "lifengzhong:/ /xxx "URL is ok. 3: Add the function in the project appdelegate:
[CPP]View Plaincopy
- -(BOOL) Application: (UIApplication *) application OpenURL: (nsurl *) URL sourceapplication: (NSString *) sourceapplication annotation: (id) annotation
- {
- if ([sourceapplication isequaltostring: @ "xxx.xxx.xxx"]) {
- Xx
- }
- return YES;
- }
This function is the handler for URL call, which is called every time another app opens the app through a URL. The parameter URL is a pass-through url,sourceapplication is the bundle identifier of the calling application, which allows the app to filter the call's application. Annotation is an additional parameter that can be attached during a call, and is not used here. 4: When another app wants to call my app, just stitch up the URL, and then open the URL, which is handy:
[CPP]View Plaincopy
- nsurl* url = [Nsurl urlwithstring: @ "lifengzhong://1,545166"];
- [[UIApplication sharedapplication] openurl:url];
Here 1,545166 is my custom parameter, you can define the format of the URL according to your own needs. The URL schema method described above is to achieve some degree of interprocess communication, but one drawback of this approach is that there can only be one process in the foreground at the same time, the application of the active call must enter the background after the call succeeds, So you can pass only the parameters that are in the URL or the parameters that are in the annotation. The switch between apps appears during the call and the user experience is not good. But better than nothing, Apple somehow left such a cut, Thanksgiving.
Transfer information between apps in iOS development 1--url Schema (Application-to-startup)