eine URL mit jeder Anwendung zu öffnen, können Sie die Startdienste nutzen. Die Funktion, die Sie betrachten möchten, ist LSOpenURLsWithRole
;
EDIT:
Sie haben die Systemconfiguration Rahmen zu einem Projekt für diese Methode verknüpfen verfügbar sein.
Apple-doc Referenz here
Zum Beispiel, wenn Sie http://www.google.com
mit Safari öffnen möchten:
//the url
CFURLRef url = (__bridge CFURLRef)[NSURL URLWithString:@"http://www.google.com"];
//the application
NSString *fileString = @"/Applications/Safari.app/";
//create an FSRef of the application
FSRef appFSURL;
OSStatus stat2=FSPathMakeRef((const UInt8 *)[fileString UTF8String], &appFSURL, NULL);
if (stat2<0) {
NSLog(@"Something wrong: %d",stat2);
}
//create the application parameters structure
LSApplicationParameters appParam;
appParam.version = 0; //should always be zero
appParam.flags = kLSLaunchDefaults; //use the default launch options
appParam.application = &appFSURL; //pass in the reference of applications FSRef
//More info on params below can be found in Launch Services reference
appParam.argv = NULL;
appParam.environment = NULL;
appParam.asyncLaunchRefCon = NULL;
appParam.initialEvent = NULL;
//array of urls to be opened - in this case a single object array
CFArrayRef array = (__bridge CFArrayRef)[NSArray arrayWithObject:(__bridge id)url];
//open the url with the application
OSStatus stat = LSOpenURLsWithRole(array, kLSRolesAll, NULL, &appParam, NULL, 0);
//kLSRolesAll - the role with which the applicaiton is to be opened (kLSRolesAll accepts any)
if (stat<0) {
NSLog(@"Something wrong: %d",stat);
}
Seine angehängte Datei: /// beim Öffnen der URL, daher öffnet sich die URL nicht. – Varun
Überprüfen Sie die aktualisierte Antwort, es sollte jetzt funktionieren. – Neha
Ja !! Es ist toll! – Genevios