繁体   English   中英

iOS >>本地通知>>如何将本地通知连接到特定对象?

[英]iOS >> Local Notifications >> How to Connect a Local Notification a Specific Object?

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

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

试试这个...

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"];
}

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM