我试图提出一个速率应用程序警报,但它没有正确打开,事实上,当我点击是按钮时,它根本打开网址,我如何让它工作?
以下是viewdidload中的调用: viewdidload中的以下代码也在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"]];
}
答案 0 :(得分:1)
创建UIAlertView时添加委托Self
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];
UIAlertView的委托方法也需要被打包
-(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"]];
}
}
答案 1 :(得分:1)
在创建UIAlertView对象时,您尚未将委托设置为self。所以 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)当你点击AlertView中的按钮时,没有调用buttonIndex方法。
更改您的代码
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];
要
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];