gpt4 book ai didi

ios - 在EKParticipant/EKAttendee中访问电子邮件

转载 作者:行者123 更新时间:2023-12-01 18:13:37 25 4
gpt4 key购买 nike

我想在EKEventKit中获取事件参与者的电子邮件地址。

我有以下代码:

if ( event.attendees.count > 0)
{
NSArray *people = event.attendees;
for(EKParticipant *person in people)
{
if ( person.participantType == EKParticipantTypePerson && person.URL.resourceSpecifier.length > 0)
{
NSString *dataString = [NSString stringWithFormat:@"event_id=%ld&name=%@&is_me=%d&email=%@&role=%@",event_id,person.name, person.isCurrentUser,person.URL.resourceSpecifier, @"attendee"];
//<DO SOMETHING USEFUL WITH dataString>;
}
}
}

当我运行代码时,人员将填充以下数据:
EKAttendee <0x17809acc0> {UUID = 4F657EA4-452A-412B-A9AA-FEC5551DC096; name = A. Real Person; email = realperson@therightdomain.com; status = 0; role = 0; type = 1}

如何访问电子邮件字段?

我尝试(如上所述)使用URL.resourceSpecifier,但这通常是一些奇怪的字符串,绝对不是电子邮件地址。

最佳答案

EKParticipant对象的“描述”是各种属性列表。我尝试了几种不同的方法,将列表解析为包含key:value对的对象,但未成功。所以我写了以下内容:

                            // This is re-useable code that converts any class description field into a dictionary that can be parsed for info
NSMutableDictionary *descriptionData = [NSMutableDictionary dictionary];
for (NSString *pairString in [person.description componentsSeparatedByString:@";"])
{
NSArray *pair = [pairString componentsSeparatedByString:@"="];
if ( [pair count] != 2)
continue;
[descriptionData setObject:[[pair objectAtIndex:1] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] forKey:[[pair objectAtIndex:0]stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];
}

有了这个,我只需获得电子邮件地址
    [descriptionData valueForKey:@"email"]

关于ios - 在EKParticipant/EKAttendee中访问电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25294011/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com