Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to handle push payload when the app closed?

i am sending push payload to my users with the follow content :

{"aps": {"alert": "Go To Google", "sound": "Default","url":"http://www.google.com"}}

everything goes well when the pp is running but in the background. if i am receiving the push and the app is closed i am open it and nothing happen. i am trying to redirect to this url in the payload. again when the app is running from the background it goes well.

this is the implementation so far AppDelegate.m:

-(void)Redirect:(NSString*)url{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]]; 
    NSLog(@"%@",url);
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {    
    RedirectedUri = [[userInfo objectForKey:@"aps"] objectForKey:@"url"];
    NSLog(@"%@",RedirectedUri);
    [self Redirect:RedirectedUri];    
  }

need some help please.

like image 691
or azran Avatar asked Dec 27 '22 23:12

or azran


1 Answers

Additionally, add the following to your code:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [self applicationDidFinishLaunching:application];

    if (launchOptions != nil)
    {
        NSDictionary* dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
        if (dictionary != nil)
        {
            RedirectedUri = [[dictionary objectForKey:@"aps"] objectForKey:@"url"];
            [self Redirect:RedirectedUri];
        }
    }
    return YES;
}
like image 176
tilo Avatar answered Feb 03 '23 03:02

tilo