Open solutions for other Access applications in the SDK
All along, in the development of iOS, it is not allowed to open another application in the program. Then there was the righteous who found such a feature in the private API with Class-dump. That is to use UIApplication's launchapplicationwithidentifier:suspended: to open.
The methods used are as follows:
NSString *identifier = [[NSBundle mainbundle] objectforinfodictionarykey:@ "Cfbundleidentifier"]; [[UIApplication sharedapplication] Launchapplicationwithidentifier:identifier Suspended:no]; |
After all, a private API is not a good idea, at least you will never get the App store endorsement.
At some point we may still need such a feature. As an SDK, there is actually a better solution. That is the method of using UIApplication's OpenURL:.
Let's take a look at the OpenURL and the implementation scenario. OpenURL is actually a very rich feature, in addition to the simple call Safari to open the site, you can also have Google map search, Mail, call, send text messages, open AppStore.
-(Ibaction) openmaps {//Open map Where is Apple on the map anyway? nsstring* Addresstext = @ "1 Infinite Loop, Cupertino, CA 95014″; URL encode the spaces Addresstext = [Addresstext stringbyaddingpercentescapesusingencoding:nsasciistringencoding]; nsstring* Urltext = [NSString stringwithformat:@ "http://maps.google.com/maps?q=%@", Addresstext]; Lets throw this text on the log so we can view the URL in the the event we had an issue NSLog (Urltext); [[UIApplication sharedapplication] Openurl:[nsurl Urlwithstring:urltext]]; } -(Ibaction) Openemail {//Open mail Fire off a email to Apple support [[UIApplication sharedapplication] Openurl:[nsurl urlwithstring:@ "Mailto://[email protected]"]; } -(Ibaction) Openphone {//Call Call Google 411 [[UIApplication sharedapplication] openurl:[nsurl urlwithstring:@ "tel://8004664411"]; } -(Ibaction) opensms {//Open SMS Text to Google SMS [[UIApplication sharedapplication] openurl:[nsurl urlwithstring:@ "sms://466453"]; } -(Ibaction) Openbrowser {//Open browser Lanuch any IPhone developers fav site [[UIApplication sharedapplication] openurl:[nsurl urlwithstring:@ "http://itunesconnect.apple.com"]; } |
How to make it from one app to open another app, which is actually very simple, open info.plist, add a URL types, expand the URL types, expand Item1, change the URL Item1 under identifier to URL Scheme, expand the URL Scheme, modify the contents of ITEM1 to MyApp other programs can access this custom URL through myapp://.
It's actually like the following style.
This way, just open the custom URL for the app, and the system can help us find and open the program.
Nsurl *url = [Nsurl urlwithstring:@ "MyApp:"]; [[UIApplication sharedapplication] openurl:url]; |
The advantage of being an SDK over a common application is that each application has a appid to differentiate, and we can make the best use of this appid.
We can ask third-party developers to configure such fields in their info.plist so that we can open the corresponding AppID application in our SDK interface, which, of course, requires the device to actually have this program installed.
For example, if an application is assigned a appid of 111122223333, we ask it to info.plist define the URL schemes as NDSDK111122223333, so that we can accurately identify the program in the internal code.
What's more, we can canopenurl this method to determine whether this device installed the application, if you can open, return yes, it should be installed such a program, whether it is an IPA or PXL program, should be no problem.
If we really choose to do this, it needs to be clearly documented. However, it is important to note that, perhaps as a programmer, you may not like to read the documentation, and perhaps you have tried to write a document that he did not see. At this point we should be a bit tough, so we have the following code function.
1: Check whether the user is configured with AppID
2: There is no cfbundleurlschemes field for accurately configuring info
3: Whether it can be opened correctly.
Check App ID: This is really a warning for the developer, this should not Happen in a completed app if (!kappid) { Uialertview *alertview = [[Uialertview alloc] initwithtitle:@ "Setup Error" message:@ "Missing app ID. You cannot run the app until your provide this in the code. " Delegate:self cancelbuttontitle:@ "OK" Otherbuttontitles:nil, NIL]; [Alertview show]; [Alertview release]; } else { Now check the URL scheme fb[app_id]://authorize are in the. plist and can Be opened, doing a simple check without the local app ID factored in here NSString *url = [NSString stringwithformat:@ "Fb%@://authorize", kappid]; BOOL bschemeinplist = NO; Find out if the sceme are in the plist file. nsarray* abundleurltypes = [[NSBundle mainbundle] objectforinfodictionarykey:@ "Cfbundleurltypes"]; if ([Abundleurltypes Iskindofclass:[nsarray class]] && ([abundleurltypes Count] > 0)) { nsdictionary* ABundleURLTypes0 = [Abundleurltypes objectatindex:0]; if ([ABundleURLTypes0 Iskindofclass:[nsdictionary class]]) { nsarray* abundleurlschemes = [ABundleURLTypes0 objectforkey:@ "Cfbundleurlschemes"]; if ([Abundleurlschemes Iskindofclass:[nsarray class]] && ([abundleurlschemes Count] > 0)) { NSString *scheme = [Abundleurlschemes objectatindex:0]; if ([Scheme iskindofclass:[nsstring class]] && [url Hasprefix:scheme]) { Bschemeinplist = YES; } } } } Check If the authorization callback would work BOOL Bcanopenurl = [[uiapplication sharedapplication] Canopenurl:[nsurl Urlwithstring:url]]; if (!bschemeinplist | |!bcanopenurl) { Uialertview *alertview = [[Uialertview alloc] initwithtitle:@ "Setup Error" message:@ "Invalid or missing URL scheme. You cannot run the app until your set up a valid URL scheme in your. plist. " Delegate:self cancelbuttontitle:@ "OK" Otherbuttontitles:nil, NIL]; [Alertview show]; [Alertview release]; } } |
Open solutions for other Access applications in the SDK