Run the code on program start-up

谁说胖子不能爱 提交于 2019-12-25 01:12:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!