3

我正在创建一个 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;
4

2 回答 2

5

字典中可以有多个对象,只要键都不同:

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

alarm.userInfo = userDict;
于 2012-04-24T07:43:07.113 回答
1

您需要将两个字典与单个字典结合使用,然后将该字典设置到用户信息中。

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

       alarm.userInfo=dic
于 2012-04-24T07:42:55.353 回答