【问题标题】:iOS >> Local Notifications >> How to Connect a Local Notification a Specific Object?iOS >> 本地通知 >> 如何将本地通知连接到特定对象?
【发布时间】:2013-10-15 07:41:49
【问题描述】:

在我的应用程序中,我保留了一组数据对象;根据某些操作,数据对象正在创建本地通知。我希望本地通知能够识别创建它的对象,因此当用户打开通知时 - 无论是来自应用程序处于活动状态时触发通知时弹出的 UIAlertView,还是由通知触发当应用程序在后台时弹出的视图 - 我可以打开一个显示特定对象数据的屏幕。

如何为本地通知实例定义我的相关对象?

【问题讨论】:

  • 使用通知的Notif.userinfo属性。它需要一个字典来保存对象。您可以通过 Notif.userinfo 在 Receive Notification 方法中获取此信息。

标签: ios uilocalnotification data-objects


【解决方案1】:

试试这个方法……

NSDictionary *dict=[NSDictionary dictionaryWithObject:@"YOUR OBJECT" forKey:@"YOUR KEY"];

   UILocalNotification *localNotif = [[UILocalNotification alloc] init];
    localNotif.fireDate = Pre_date;
    localNotif.timeZone = [NSTimeZone defaultTimeZone];

    // Notification details
    localNotif.alertBody = [txtRemindetText text];
    // Set the action button
    localNotif.alertAction = @"View";
    localNotif.userInfo=dict;
    localNotif.soundName = UILocalNotificationDefaultSoundName;

    // Schedule the notification
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];

AppDelegate.m

- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
    // Handle the notificaton when the app is running
    NSLog(@"Recieved Notification %@",notif);
    NSLog(@"%@",notif.userInfo);
    NSLog(@"%@",[notif.userInfo objectForKey:@"YOUR KEY"];
}

如果您有任何问题,请告诉我。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多