How to open the app in your phone with the package name

Source: Internet
Author: User

There are two ways to open apps that are currently known,

One is open through OpenURL, this has a serious problem, that is, the whitelist must be added, the app is installed on the white list and cannot be opened.

Another is the focus of today, open the app with the package name. First, the core code:

Class LSAWSC = Objc_getclass ("Lsapplicationworkspace"); NSObject* Workspace = [Lsawsc performselector:nsselectorfromstring (@"Defaultworkspace")]; BOOL Open= [Workspace respondstoselector:nsselectorfromstring (@"Openapplicationwithbundleid:")];if(open) {[Workspace performselector:nsselectorfromstring (@"Openapplicationwithbundleid:") Withobject:@"com.xxx.xxx"];}

Note: Refer to the following URL (I do not know which is original, I hope that the following posted by the original author)

iphone gets all the apps in the phone (private library) + open app via package name https://www.cnblogs.com/fuunnyy/p/5392241.html   IOS Get app-related information private Apihttps://www.cnblogs.com/qingjoin/p/4968570.html

Just pass in the package name of the app you want to open.

But the above method also has some small flaw, just do not know whether to open the app, the following two kinds of situations are not open app:

1. The app is not yet installed.

2. The app is downloading and installing.

The next step is to optimize the problem.

There are several characteristics of the above methods, as follows:

1. When opening the app, it will take some time to jump (how much?). This is not necessarily, depends on the time you use the real situation, but 1 seconds should be enough?

2. If the jump is successful, your app will enter the background, if it fails to open, your app is still active.

So, follow these two features to think of the following solution:

After the program enters the backstage and enters the foreground to make the mark (with Nsuserdefault can), after opens the app the operation time Delay performs the following action:

Dispatch_after (Dispatch_time (Dispatch_time_now, (int64_t) (1.0* nsec_per_sec)), Dispatch_get_main_queue (), ^{nsstring*state = @ "0|1";//read the stored marks here 0|1 or other marks you have made    if([State isequal:@"0"]) {NSLog (@"Go Backstage"); }    Else if([State isequal:@"1"]) {NSLog (@"Active State"); }});

This will tell you if the app has been opened.

How to open the app in your phone with the package name

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.