示例示例iOS 通知传值是指在 iOS 应用程序中,通过本地通知或远程推送通知来传递数据。本地通知传值的实现代码如下:
iOS 通知传值是指在 iOS 应用程序中,通过本地通知或远程推送通知来传递数据。
本地通知传值的实现代码如下:
// 创建本地通知
UILocalNotification *notification = [[UILocalNotification alloc] init];
// 设置触发通知的时间
notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:10.0];
// 时区
notification.timeZone = [NSTimeZone defaultTimeZone];
// 通知内容
notification.alertBody = @"本地通知测试";
// 通知被触发时播放的声音
notification.soundName = UILocalNotificationDefaultSoundName;
// 内容可更改
notification.alertAction = @"打开应用";
// 启动图片
notification.alertLaunchImage = @"Default";
// 动作按钮
notification.hasAction = YES;
// 通知上绑定数据
notification.userInfo = @{@"key1":@"value1",@"key2":@"value2"};
// 添加通知到系统队列中,系统会在指定的时间触发
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
远程推送通知传值的实现代码如下:
// 创建远程推送通知
UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:myTypes];
// 发送远程推送通知
NSDictionary *pushDict = [NSDictionary dictionaryWithObjectsAndKeys:
@"value1",@"key1",
@"value2",@"key2",
nil];
[application presentLocalNotificationNow:pushDict];
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(50条)