Resolved IApplication may not respond to '+mainWindow'

Discussion in 'iOS Programming' started by webznz, Apr 18, 2011.

  1. webznz, Apr 18, 2011
    Last edited: Apr 18, 2011

    webznz macrumors member

    Mar 8, 2011
    Hi im getting this error,UIApplication may not respond to '+mainWindow' with my action sheet , but im not really sure why. any help would be greatly appreciated.

    #import "cookieTestAppDelegate.h"
    @implementation cookieTestAppDelegate
    @synthesize window;
    #pragma mark -
    #pragma mark Application lifecycle
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
        // Override point for customization after application launch.
    	//NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
    	//NSString *MessageString = [ud stringForKey:"PSTextFieldSpecifier"];
    	//construct the web service url
    	//sets from the setting entry
    	NSString *startURL = (@"http://myiplinkhere/?func=******");
    	NSURL *url = [NSURL URLWithString:startURL];
    	//create a request object with that url
    	NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30];
    	//clear out the exisiting connection if there is on
    	if (connectionInProgress) {
    		[connectionInProgress cancel];
    		[connectionInProgress release];
    	//Instantiate the object to hold all incoming data
    	[cookieData release];
    	cookieData = [[NSMutableData alloc]init];
    	//create and initiate the connection - non-blocking
    	connectionInProgress = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
        [self.window makeKeyAndVisible];
        return YES;
    - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    	[cookieData appendData:data];
    - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    	//we are just checking to make sure we are getting the SML
    	NSString *cookieCheck = [[[NSString alloc] initWithData:cookieData encoding:NSUTF8StringEncoding] autorelease];
    	NSLog(@"yum yum feed me more cookie!! %@",cookieCheck);
    - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
    	[connectionInProgress release];
    	connectionInProgress = nil;
    	[cookieData release];
    	cookieData = nil;
    	NSString *errorString = [NSString stringWithFormat:@"Fetch failed: %@", [error localizedDescription]];
    	UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:errorString delegate:nil cancelButtonTitle:@"OK" destructiveButtonTitle:nil otherButtonTitles:nil];
    	[actionSheet showInView:[UIApplication mainWindow]];[B][COLOR="Red"] //UIApplication may not respond to '+mainWindow'[/COLOR][/B]
    	[actionSheet autorelease];
    //***** other code till end.
  2. chown33 macrumors 604

    Aug 9, 2009
    How to solve problems like this:
    1. Open the class reference doc (UIApplication in this case).
    2. Search for the expected method or property (mainWindow in this case).
    3. If found, read the description carefully (some detail may differ from your expectation, such as - instead of +, or a different letter-case than you expected).
    4. If not found, open the class reference doc for the superclass and go to step 2.
    5. If not found in any class or superclass, then the reason for the message is simple: the class does not have the method or property you expected.

    If you reach step #5, you'll have to modify your problem-solving procedure. You think it is method xyzzy, but it really might have method xyz, or zzy.

    In your case, it's not clear what you're trying to do. You might mean the keyWindow property of the UIApplication instance, but if not, you'll have to explain exactly what you're trying to accomplish.

    In general, it's always a good idea to describe exactly what you're trying to accomplish.
  3. webznz, Apr 18, 2011
    Last edited by a moderator: Apr 18, 2011

    webznz thread starter macrumors member

    Mar 8, 2011
    sorry, basically I'm trying to initiate a connection to my server in application:didFinishLaunchingWithOptions: this is to instantiate my cookie that im using to sync devices to my app, if someone gives out their register code then their device will be bounced off my server when the new device with their reg code syncs... thus not allowing them to make queries to the database.., if there is no response then connection:didFailWithError: will catch the fail error and the action sheet should pop up on the main screen.

    Thanks for the hep will have another look at my code with your response in mind.


    so found a solution in some sample code refereed from in the reference documentation.

    it was as easy as swapping
    [actionSheet showInView:[UIApplication mainWindow]]
    [actionSheet showInView:self.window];
    I also realized that i was calling the wrong name for the window as it was initialized as window in my .h file not mainWindow... think i need a nap .. :)

Share This Page