在加载主应用程序视图之前获取一些设备信息

发布于 2024-11-07 14:16:06 字数 384 浏览 0 评论 0原文

Objective-c 对我来说还很陌生,所以我很可能会问一个简单得荒谬的问题,但在浏览了网络和一些书籍后,我在某种程度上有点困惑。很可能是由于我对 obj-c 严重缺乏了解。所以...对此的任何帮助都将非常方便...

我想做的就是在应用程序启动时但在主应用程序之前获取有关应用程序运行的设备的一些简单信息(使用 [UIDevice currentDevice])视图已加载。很简单的事情,嗯,但老实说,我不知道如何做到这一点!然后,我希望在整个应用程序及其视图中提供任何可用的信息(在变量中?不太确定这是否是 obj-c 的正确术语)。再说一次,我真的不太知道如何做。

我有网络开发背景,所以这在很大程度上对我来说是非常新的。所以...是的,任何提示/指示、帮助等都会非常有用!

预先感谢,抱歉我的问题!

Objective-c is pretty new to me so I may well be asking an absurdly simple question but having been looking over the web and in some books I'm a bit stumped to some degree. Quite probably due to my severe lack of knowledge with obj-c. So... any help with this one will be really handy...

All I want to do is get some simple info about the device the app is running on (using [UIDevice currentDevice]) on the app launch but before the main app view is loaded up. Simple stuff huh but in all honesty I have not got the idea quite how to do this! I then want whatever info I have to be availiable (In a variable? Not too sure if thats the correct term with obj-c) throughout the app and its views. Again, I don't really have much of an idea how.

I come form a web dev background so this is very new to me to a large degree. So... yeah, any tips/pointers, help etc would be ridiculously useful!

Thanks in advance, sorry for my n00b question!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜吻♂芭芘 2024-11-14 14:16:06

该位置可能位于您的应用程序委托 -application:didFinishLaunchingWithOptions: 方法中。当您的应用程序完成启动时会调用此方法,并且(通常)负责将主视图添加到应用程序窗口。您可以将信息放入应用程序委托的实例变量中。您可以通过调用 [[UIApplication sharedApplication] delegate] 从程序中的任何位置获取对应用程序委托的引用。示例实现可能如下所示:

// In MyAppDelegate.m

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

    //Get your information, potentially put it into an
    //instance variable of the App Delegate

    //Add the main view to the view hierarchy
    [self.window addSubview:viewController.view];
    [self.window makeKeyAndVisible];

    return YES;
}

The place for this would probably be in your App Delegates -application:didFinishLaunchingWithOptions: method. This method gets called when your app finishes launching and is (generally) responsible for adding your main view to the application window. You can put the information into an instance variable of your app delegate. You can get a reference to your app delegate from anywhere in your program by calling [[UIApplication sharedApplication] delegate]. An example implementation might look something like this:

// In MyAppDelegate.m

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

    //Get your information, potentially put it into an
    //instance variable of the App Delegate

    //Add the main view to the view hierarchy
    [self.window addSubview:viewController.view];
    [self.window makeKeyAndVisible];

    return YES;
}
蓝眼睛不忧郁 2024-11-14 14:16:06

您也许可以使用 viewController 方法“viewWillAppear”。它将希望与“viewDidUnload”方法位于同一区域,该方法将位于连接到主视图的任何 *ViewController.m 文件中。

可能您需要在调用 UIApplicationMain 之前在 main() 例程中执行此操作。

You might be able to use the viewController method "viewWillAppear". it will want to be in the same area as the "viewDidUnload" method, which will be in whatever *ViewController.m file is connected to the main view.

Possibly you'll need to do it in the main() routine, before the call the UIApplicationMain.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文