开发者

Unable to show UIAlertView

in my app i am using validation keys to download content from a server using Wi-Fi. I need to show a UIAlert if the licence keys are wrong or if the wi-fi is not available. I have written the coed for displaying the alert view but the alert is not being displayed... This is scking the blood out my head... Can anyone help please....the control is going over this line, but stil开发者_如何学运维l the alert is not being displayed.

-(void)connectionDidFinishLoading:(NSURLConnection *)connection{

NSFileManager *fileManager = [NSFileManager defaultManager];

NSString *documentsDirectory=   [[[UIApplication sharedApplication] delegate] applicationDocumentsDirectory];   //[pathToStore objectAtIndex:0];

NSString *path = [documentsDirectory stringByAppendingFormat:@"packages"];

NSString *packagePath = [NSString stringWithFormat:@"%@/%@", path,isbnTemp];

[recievedData writeToFile:[documentsDirectory stringByAppendingPathComponent:@"file.zip"] atomically:YES];
NSString *zipPath=[documentsDirectory stringByAppendingPathComponent:@"file.zip"];

[fileManager createDirectoryAtPath:documentsDirectory withIntermediateDirectories:NO attributes:nil error:nil];

    ZipArchive *zipArchive = [[ZipArchive alloc]init];

if([zipArchive UnzipOpenFile:zipPath]){

    if([zipArchive UnzipFileTo:packagePath overWrite:YES]){

        [self loadContent];


    }
    else{
        NSLog(@"Unable to UnArchieve the packages");
    }


}
else  {


    NSLog(@"Failure To Open Archive");
    UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Your ISBN and/or Licence Key are incorrect" message:Nil delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil];
    [alert show];
    [alert release];    
}

}


Are you trying to show the UIAlertView in a method that is being called from a thread other than the main thread? For example, if you are trying to show the UIAlertView in an asynchronous callback, it could be running on a separate thread.

If so, you need to move the code that shows the UIAlertView to a separate selector, and call it on the main thread using one of the performSelectorOnMainThread: methods.

For example, add the following method to your class:

-(void)showAlert {
    UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Your ISBN and/or Licence Key are incorrect" message:Nil delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil];
    [alert show];
    [alert release];
}

And then change the last else clause in your current code so that it uses:

[self performSelectorOnMainThread:@selector(showAlert) withObject:nil waitUntilDone:NO];

See the NSObject class reference for more information on the performSelectorOnMainThread: methods.


After you've created the alert could you check for a NULL pointer in the alert variable? Maybe you need to specify a message? Other than that I can't see anything wrong with the code you've posted.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜