简体   繁体   中英

Show a page when OK button of push notification is pressed

I want to show thanku.html page when the user provides Push Notifications permission (ie. when user taps on OK button to allow the notifications). This page should be displayed only once.

Problem faced:

  1. thanku.htlml page reloads in background before pressing the OK button.
  2. If notifications permission is accepted, thanku.html page opens every time the app is launched. Whereas, it should not be displayed on relaunch.

Code I have written:

- (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];
}

In viewdidload of view controller:

 [self showAtAppearTime];

and the showAtAppearTime is:

- (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];
}

and the setEmptyWebview is

NSString *urlAddress = @"";

NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];     
- (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
} }

Hope this will help you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM