将多个userInfo存储在本地通知中

时间:2012-04-24 07:36:28

标签: iphone uilocalnotification

我正在创建一个UILocalNotification,我需要为此设置多个userInfo,我该怎么做?

    // Create a new notification

    UIApplication* app = [UIApplication sharedApplication];

    UILocalNotification *alarm = [[UILocalNotification alloc] init];

    alarm.fireDate = date;        
    alarm.timeZone = [NSTimeZone localTimeZone];
    alarm.alertBody = msg;        
    alarm.alertAction = @"View";            
    alarm.repeatInterval = NSYearCalendarUnit;
    alarm.soundName=@"happyBirthday.wav";
    alarm.applicationIconBadgeNumber = 1;    

   NSDictionary *userDict = [NSDictionary dictionaryWithObject:detailperson forKey:@"msg"];
   NSDictionary *userDictName = [NSDictionary dictionaryWithObject:detailperson2 forKey:@"name"];

   alarm.userInfo = userDict;
   alarm.userInfo = userDictName;

2 个答案:

答案 0 :(得分:5)

只要键完全不同,您就可以在字典中拥有多个对象:

NSDictionary *userDict = [NSDictionary dictionaryWithObjectsAndKeys:detailperson, @"msg", detailperson2, @"name", nil];

alarm.userInfo = userDict;

答案 1 :(得分:1)

你需要使用combine两个字典与单个Dictionary结合,然后将该字典设置为用户信息。

        NSDictionary *dic=[NSDictionary dictionaryWithObjectsAndKeys:dic1,@"first",dic2,@"second", nil];

       alarm.userInfo=dic