需要建议将gmail帐户集成到iOS开发中 [英] Need suggestion to integrate gmail account in iOS developlment

查看:94
本文介绍了需要建议将gmail帐户集成到iOS开发中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iOS编程的新手,只想做点有趣的事情. 我想为iPhone开发一个邮件客户端应用程序,它可以添加电子邮件帐户,例如gmail和Yahoo等.我在网上搜索了一段时间,还发现了一些

I am new to iOS programming, and just want to do something fun. I want to develop a mail client app for iPhone, it can add email accounts such as gmail and Yahoo and so on. I searched online for a while and also find some answers, before I dive into the details I just want someone who has similar experience give me some suggestions about which method is the best.

谢谢

推荐答案

我最近实现了gmail api,以在我的tableview中获取gmail联系人及其电子邮件. Gmail api简而言之,这就是为什么您可能没有适当的文档的原因.

I have recently implemented gmail api to fetch gmail contacts and their email in my tableview. Gmail api is depricated, thats why you might have not got any proper documentation for that.

要实现gmail,请使用带有Gdata标头的libGDataTouchStaticLib.a库(在Google上搜索该库,否则向我发送您的电子邮件,我将向您发送其zip).

To implement gmail use libGDataTouchStaticLib.a library, with Gdata headers (search on google for that otherwise send me your email i will send you its zip).

获取gmail详细信息的代码如下

The code to get gmail details are as follows

- (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
    }


}

这篇关于需要建议将gmail帐户集成到iOS开发中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆