我正在使用Objective-C中的ios 10 Rich Media推送通知。我想在按下 UNNotificationAction 按钮时打开一个URL。我在followig方法中得到了点击响应:
-(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler{
NSDictionary * userInfo = response.notification.request.content.userInfo;
NSArray *btnArray = userInfo[@"aps"][@"btnArr"];
NSString *urlString = [btnArray valueForKey:@"url"]; //Supose url = www.google.com
NSURL *url = nil;
if ([urlString hasPrefix:@"http://"] || [urlString hasPrefix:@"https://"]) {
url = [NSURL URLWithString:urlString];
} else {
url = [NSURL URLWithString:[NSString stringWithFormat:@"https://%@",urlString]]; //now url = https://www.google.com
}
// Here the url that will be hit = https://www.google.com
if (![[UIApplication sharedApplication] openURL:url]) {
if ([[url absoluteString] isEqual:[NSNull null]] || [[url absoluteString] isEqualToString:@""] || [[url absoluteString] length] == 0) {
NSLog(@"action url is empty");
} else {
NSLog(@"%@%@",@"Failed to open url:",[url description]);
}
}
}
但它仅在应用程序仅处于前台状态时才起作用。我想在应用程序的所有状态(即非活动,活动和背景状态)中打开URL。 任何人都可以帮助我实现我的目标。如果可能,请提供任何参考颂歌,