Reputation: 27
Im trying to put in a rate App alert, but its not opening properly, in fact when I click the Yes button it dosnt open the url at all, How do I make it work?
Below is the call in the viewdidload: The below code in viewdidload is also in app delegate
[super viewDidLoad];
//rate app
NSUserDefaults *prefsr = [NSUserDefaults standardUserDefaults];
NSInteger launchCount = [prefsr integerForKey:@"launchCount"];
if (launchCount >= 1) {
UIAlertView *alertRate = [[UIAlertView alloc] initWithTitle:@"Like this app?" message:@"Rate on the app store." delegate:nil cancelButtonTitle:@"No, thanks" otherButtonTitles:@"Yes",@"Remind me later", nil];
[alertRate show];
}
-(void)alertViewRate:(UIAlertView *)alertViewRate clickedButtonAtIndex:(NSInteger)buttonIndexP{
if (buttonIndexP == 2) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://www.google.com"]];
}
else if (buttonIndexP == 1){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://www.google.com"]];
}
Upvotes: 1
Views: 203
Reputation: 151
You haven't set the delegate to self while you are creating UIAlertView object. So -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex method is not getting called when you click on buttons in the AlertView.
Change your code From
UIAlertView *alertRate = [[UIAlertView alloc] initWithTitle:@"Like this app?" message:@"Rate on the app store." delegate:nil cancelButtonTitle:@"No, thanks" otherButtonTitles:@"Yes",@"Remind me later", nil];
To
UIAlertView *alertRate = [[UIAlertView alloc] initWithTitle:@"Like this app?" message:@"Rate on the app store." delegate:self. cancelButtonTitle:@"No, thanks" otherButtonTitles:@"Yes",@"Remind me later", nil];
Upvotes: 1
Reputation: 1483
Add the delegate Self while creating the UIAlertView
UIAlertView *alertRate = [[UIAlertView alloc] initWithTitle:@"Like this app?" message:@"Rate on the app store." delegate:self cancelButtonTitle:@"No, thanks" otherButtonTitles:@"Yes",@"Remind me later", nil];
[alertRate show];
Delegate method for UIAlertView also need to be chnaged
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 2) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://www.google.com"]];
}
else if (buttonIndex == 1){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://www.google.com"]];
}
}
Upvotes: 1