PDA

View Full Version : [Resolved] IApplication may not respond to '+mainWindow'




webznz
Apr 18, 2011, 05:12 PM
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]]; //UIApplication may not respond to '+mainWindow'
[actionSheet autorelease];
}


//***** other code till end.
@end



chown33
Apr 18, 2011, 05:57 PM
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.

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.

webznz
Apr 18, 2011, 06:14 PM
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.

EDIT:

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

it was as easy as swapping
[actionSheet showInView:[UIApplication mainWindow]]
with
[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 .. :)