按下按钮的OK按钮时显示页面

时间:2016-03-11 08:00:03

标签: ios objective-c push-notification

我希望在用户提供推送通知权限时显示thanku.html页面(即,当用户点击“确定”按钮以允许通知时)。 此页面只能显示一次。

面临的问题:

    在按下“确定”按钮之前,
  1. thanku.htlml页面在后台重新加载。
  2. 如果接受通知权限,则每次启动应用时都会打开thanku.html页面。然而,它不应该在重新启动时显示。
  3. 我编写的代码:

    - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
    {
        // For show the thank you page
        NSArray *controllers = [SlideNavigationController sharedInstance].viewControllers;
    
        for (id obj in controllers) {
            if([obj isKindOfClass:[ViewController class]])
            {
                ViewController *controller = (ViewController *)obj;
    
                controller.titleOfController = @"Thank you";
                controller.urlStr = @"http://www.7dci.com.au/lagarto/thankyou.html";
                [controller showAtAppearTime];
    
                [[SlideNavigationController sharedInstance] popToViewController:controller animated:YES];
                return;
            }
        }
    
        ViewController *controller = [[UIStoryboard storyboardWithName:@"Main" bundle:nil ] instantiateViewControllerWithIdentifier:@"ViewController"];
        controller.titleOfController = @"Thank you";
        controller.urlStr = @"http://www.7dci.com.au/lagarto/thankyou.html";
        [controller showAtAppearTime];
        [[SlideNavigationController sharedInstance] pushViewController:controller animated:YES];
    }
    

    viewdidload视图控制器中:

     [self showAtAppearTime];
    

    showAtAppearTime是:

    - (void)showAtAppearTime
    {
        [webView setDelegate:self];
    
        [self setEmptyWebview];
    
        titleLbl.text = @"saurabh";
        if(self.titleOfController.length > 0)
            titleLbl.text = self.titleOfController;
        [[NSURLCache sharedURLCache] removeAllCachedResponses];
        NSString *urlAddress = @"http://7dci.com.au/lagarto/menu.html";
        if(self.urlStr.length > 0)
            urlAddress = self.urlStr;
        NSURL *url = [NSURL URLWithString:urlAddress];
        NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
        [webView loadRequest:requestObj];
    }
    

    setEmptyWebview

    NSString *urlAddress = @"";
    
    NSURL *url = [NSURL URLWithString:urlAddress];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    [webView loadRequest:requestObj];     
    

1 个答案:

答案 0 :(得分:0)

- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
if(![[[NSUserDefaults standardUserDefaults] objectForKey:@"isFirstTime"] isEqualToString:@"Yes"]){
    [[NSUserDefaults standardUserDefaults] setObject:@"Yes" forKey:@"isFirstTime"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    //Write your required code to set html here
} }

希望这会对你有所帮助