开发者

Getting some device info before the main app view is loaded up

开发者 https://www.devze.com 2023-03-06 13:27 出处:网络
Objective-c is pretty new to me so I may well be asking an absurdly simple qu开发者_Go百科estion but having been looking over the web and in some books I\'m a bit stumped to some degree. Quite probabl

Objective-c is pretty new to me so I may well be asking an absurdly simple qu开发者_Go百科estion 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!


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消