简体   繁体   English

需要建议将gmail帐户集成到iOS开发中

[英]Need suggestion to integrate gmail account in iOS developlment

I am new to iOS programming, and just want to do something fun. 我是iOS编程的新手,只想做点有趣的事情。 I want to develop a mail client app for iPhone, it can add email accounts such as gmail and Yahoo and so on. 我想为iPhone开发一个邮件客户端应用程序,它可以添加电子邮件帐户,例如gmail和Yahoo等。 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. 我在网上搜索了一段时间,也找到了一些答案 ,然后再深入研究细节,我只希望有类似经验的人给我一些关于哪种方法最好的建议。

thanks 谢谢

I have recently implemented gmail api to fetch gmail contacts and their email in my tableview. 我最近实现了gmail api,以便在我的tableview中获取gmail联系人和他们的电子邮件。 Gmail api is depricated, thats why you might have not got any proper documentation for that. Gmail api已被描述,这就是为什么您可能没有任何适当的文档。

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,请使用带有Gdata标头的libGDataTouchStaticLib.a库(在Google上搜索该库,否则向我发送电子邮件,我将向其发送zip)。

The code to get gmail details are as follows 获取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
    }


}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM