bahmet
bahmet

Reputation: 3

UrbanAirship Push with URL on IOS

I am using UrbanAirship to send push messages to my applications. my setting works both on development and production. I need to send web url's as push message. when user opens the message I want it to redirect to the url that I added. I added this code to my appdelegate.

`- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
      NSLog(@"userInfo:%@",[userInfo description]);
      NSLog(@"alert:%@",[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]);
      NSLog(@"alert:%@",[[userInfo objectForKey:@"aps"] objectForKey:@"url"]);
}

and tried to send push like

{
    "aps": 
    {
        "alert": "take a look at this site ",
        "url": "www.mysite.com"
    }
}

I received the alert message but again it opened the application not the url. Can you advice me how to send the push message with the url and make it open that url?

Upvotes: 0

Views: 775

Answers (1)

Balazs Nemeth
Balazs Nemeth

Reputation: 2332

There is two way to do that

Open the url with a safari (not tested code):

     - (void)application:(UIApplication *)application didReceiveRemoteNotification: (NSDictionary *)userInfo
    { 
     NSLog(@"userInfo:%@",[userInfo description]); 
     NSLog(@"alert:%@",[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]);
     NSLog(@"url:%@",[[userInfo objectForKey:@"aps"] objectForKey:@"url"]); 
     webViewController.url = [NSURL URLWithString:[[userInfo objectForKey:@"aps"] objectForKey:@"url"]];
     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSURL URLWithString:[[userInfo objectForKey:@"aps"] objectForKey:@"url"]];
    }

Or you must to handle it on your app:

- (void)application:(UIApplication *)application didReceiveRemoteNotification: (NSDictionary *)userInfo{ 
     NSLog(@"userInfo:%@",[userInfo description]); 
     NSLog(@"alert:%@",[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]);
     NSLog(@"url:%@",[[userInfo objectForKey:@"aps"] objectForKey:@"url"]); 
     webViewController.url = [NSURL URLWithString:[[userInfo objectForKey:@"aps"] objectForKey:@"url"]];

}

And e.g in your WebViewController need the following methods

    - (void)viewWillAppear:(BOOL)animated { 
    [super viewWillAppear:animated];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    [webView loadRequest:requestObj];
    }

Of course, on your WebViewController.h must be a

    IBOutlet UIWebView *webView;

with full screen, or what you want...

Upvotes: 1

Related Questions