在程序启动时运行代码 [英] Run the code on program start-up

查看:135
本文介绍了在程序启动时运行代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.google.com"]];

打开Safari并重定向到URL。

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?

一开始,我有 HelloWorldViewController文件.h, HelloWorldViewController.m和XCode 4生成的 HelloWorldViewController.xlb。

At the beginning, I have the file of "HelloWorldViewController.h", "HelloWorldViewController.m" and "HelloWorldViewController.xlb" that are generated by XCode 4.

已更新,我将以下代码添加到xxxx.m文件中,但不起作用,请帮助

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"]];
}


推荐答案

好然后在statup上运行它。...

Ok, if you want to run it on statup then....

-(BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

这在应用程序委托中。...不确定为什么您将要执行此操作,还是Apple是否会批准这样的应用程序...?

This is in the App Delegate....not sure why you would want to do this or whether Apple would even approve such an app...?

如果要显示Web内容,则可以使用UIWebview并加载该网址....

If you want to show web content then you can use a UIWebview and load the URL into that....

这篇关于在程序启动时运行代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆