问题
I’m using
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.google.com"]];
to open Safari and redirect to a URL.
Where can I put this code in so as to let the program run this code at start-up?
At the beginning, I have the file of "HelloWorldViewController.h", "HelloWorldViewController.m" and "HelloWorldViewController.xlb" that are generated by XCode 4.
Updated, I added the code as below to xxxx.m file, but not works, please help
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.google.com"]];
}
回答1:
Ok, if you want to run it on statup then....
-(BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
This is in the App Delegate....not sure why you would want to do this or whether Apple would even approve such an app...?
If you want to show web content then you can use a UIWebview and load the URL into that....
来源:https://stackoverflow.com/questions/6355151/run-the-code-on-program-start-up