打开网址与本地通知ios
发布时间:2020-12-14 18:00:33 所属栏目:百科 来源:网络整理
导读:我一直在寻找答案,但我似乎找不到答案.我想要做的是让我的应用程序在后台运行应用程序时发送本地通知,当用户打开通知时,它会将他们带到网站.我已经完成了所有设置,但它一直打开应用程序,而不是去网站. 我的问题是,这甚至可能吗?如果是这样,请问下面我的代码
我一直在寻找答案,但我似乎找不到答案.我想要做的是让我的应用程序在后台运行应用程序时发送本地通知,当用户打开通知时,它会将他们带到网站.我已经完成了所有设置,但它一直打开应用程序,而不是去网站.
我的问题是,这甚至可能吗?如果是这样,请问下面我的代码出错了?谢谢您的帮助. 码: – (void)applicationDidEnterBackground:(UIApplication *)应用程序 NSDate *date = [NSDate date]; NSDate *futureDate = [date dateByAddingTimeInterval:3]; notifyAlarm.fireDate = futureDate; notifyAlarm.timeZone = [NSTimeZone defaultTimeZone]; notifyAlarm.repeatInterval = 0; notifyAlarm.alertBody = @"Visit Our Website for more info"; [app scheduleLocalNotification:notifyAlarm]; if ( [notifyAlarm.alertBody isEqualToString:@"Visit Our Website for more info"] ) { [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://www.bluemoonstudios.com.au"]]; } 解决方法
在您的业务逻辑中
-(void)scheduleNotificationForDate:(NSDate *)fireDate{ UILocalNotification *notification = [[UILocalNotification alloc] init]; notification.fireDate = fireDate; notification.alertAction = @"View"; notification.alertBody = @"New Message Received"; notification.userInfo = @{@"SiteURLKey": @"http://www.google.com"}; [[UIApplication sharedApplication] scheduleLocalNotification:notification]; } 在你的AppDelegate中 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey]; if(notification != nil){ NSDictionary *userInfo = notification.userInfo; NSURL *siteURL = [NSURL URLWithString:[userInfo objectForKey:@"SiteURLKey"]]; [[UIApplication sharedApplication] openURL:siteURL]; } } -(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{ NSDictionary *userInfo = notification.userInfo; NSURL *siteURL = [NSURL URLWithString:[userInfo objectForKey:@"SiteURLKey"]]; [[UIApplication sharedApplication] openURL:siteURL]; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- c# – 示例代码中是否需要Task.WhenAll?
- 启用Flash Player 11.3的全屏键盘输入注意事项
- c# – ASP.NET MVC路由/ SEO友好URL
- ruby-on-rails – 用于RSpec的未定义方法instance_double :
- ruby-on-rails – RSpec:undefined方法`infer_spec_type_f
- Flex4之元数据标签:[ArrayElementType] [Bindable] [Defau
- 数组 – PostgreSQL可以索引数组列吗?
- swift3 – swift 3和CGContextEOClip
- objective-c – 国际化:在Simulator中仅显示键名而不是本地
- reactjs – 何时使用React“componentDidUpdate”方法?