ios - 需要建议在 iOS 开发中集成 Gmail 帐户

标签 ios iphone objective-c gmail

我是 iOS 编程的新手,只想做点有趣的事情。 我想为iPhone开发一个邮件客户端应用程序,它可以添加gmail和Yahoo等电子邮件帐户。我在网上搜索了一会儿,也找到了一些answers ,在我深入细节之前,我只想让有类似经验的人给我一些建议,告诉我哪种方法最好。

谢谢

最佳答案

我最近实现了 gmail api 以在我的表格 View 中获取 gmail 联系人及其电子邮件。 Gmail api 已被删除,这就是为什么您可能没有任何适当的文档。

要实现 gmail,请使用带有 Gdata header 的 libGDataTouchStaticLib.a 库(在谷歌上搜索,否则请将您的电子邮件发送给我,我会向您发送其 zip)。

获取gmail详情的代码如下

- (void)getGoogleContacts {

    GDataServiceGoogleContact *service = [self contactService];
    GDataServiceTicket *ticket;

    BOOL shouldShowDeleted = TRUE;

    // request a whole buncha contacts; our service object is set to
    // follow next links as well in case there are more than 2000
    const int kBuncha = 2000;

    NSURL *feedURL = [GDataServiceGoogleContact contactFeedURLForUserID:kGDataServiceDefaultUser];

    GDataQueryContact *query = [GDataQueryContact contactQueryWithFeedURL:feedURL];
    [query setShouldShowDeleted:shouldShowDeleted];
    [query setMaxResults:kBuncha];

    ticket = [service fetchFeedWithQuery:query
                                delegate:self
                       didFinishSelector:@selector(contactsFetchTicket:finishedWithFeed:error:)];

    [self setContactFetchTicket:ticket];
}

- (void)setContactFetchTicket:(GDataServiceTicket *)ticket {

    mContactFetchTicket = ticket;
}

- (GDataServiceGoogleContact *)contactService {

    static GDataServiceGoogleContact* service = nil;

    if (!service) {

        service = [[GDataServiceGoogleContact alloc] init];

        [service setShouldCacheResponseData:YES];
        [service setServiceShouldFollowNextLinks:YES];
    }

    // update the username/password each time the service is requested
    NSString *username = [txtUserName text];
    NSString *password = [txtPasswrod text];

    [service setUserCredentialsWithUsername:username
                                   password:password];

    return service;
}


// contacts fetched callback
- (void)contactsFetchTicket:(GDataServiceTicket *)ticket
           finishedWithFeed:(GDataFeedContact *)feed
                      error:(NSError *)error {

    if (error) {

        NSDictionary *userInfo = [error userInfo];
        NSLog(@"Contacts Fetch error :%@", [userInfo objectForKey:@"Error"]);
        if ([[userInfo objectForKey:@"Error"] isEqual:@"BadAuthentication"]) {

            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error!"
                                                                message:@"Authentication Failed"
                                                               delegate:self
                                                      cancelButtonTitle:@"Ok"
                                                      otherButtonTitles:nil, nil];
            [alertView show];

        } else {

            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error!"
                                                                message:@"Failed to get Contacts."
                                                               delegate:self
                                                      cancelButtonTitle:@"Ok"
                                                      otherButtonTitles:nil, nil];
            [alertView show];
        }

    } else {

        NSArray *contacts = [feed entries];
        NSLog(@"Contacts Count: %d ", [contacts count]);
        [mutAryGoogleContacts removeAllObjects];
        for (int i = 0; i < [contacts count]; i++) {

            NSMutableDictionary *aDictContactDetails=[NSMutableDictionary dictionary];


            GDataEntryContact *contact = [contacts objectAtIndex:i];
            // Email
            GDataEmail *email = [[contact emailAddresses] objectAtIndex:0];
            NSString* ContactEmail = [email address];
            if (ContactEmail) {
                [aDictContactDetails setObject:ContactEmail forKey:@"email"];




            // Name
            NSString *ContactName = [[[contact name] fullName] contentStringValue];
            if (ContactName) {
                [aDictContactDetails setObject:ContactName forKey:@"friendName"];

            }
            [mutAryGoogleContacts addObject:aDictContactDetails];

            }

        }

       //Push to next vc or do whatever you want
    }


}

关于ios - 需要建议在 iOS 开发中集成 Gmail 帐户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21873323/

相关文章:

objective-c - iPhone NSDate 例如。下周五

ios - UIView 可以复制吗?

ios - 如何设置每两周一次本地通知

ios - 台风参数注入(inject)与初始化器崩溃应用程序

ios - 创建动画队列

ios - 为什么 pod lib create 不能为 cocoapod 正确创建目录?

IOS:更改 View 的建议

ios - 如何使 UILabel 在 UIView 上居中

ios - 如何检测 UIButton 背景图片的变化?

iphone - 以编程方式读取 iPhone 设置(精确设置->常规->日期和时间->自动设置)