【问题标题】:Need suggestion to integrate gmail account in iOS developlment需要建议在 iOS 开发中集成 gmail 帐户
【发布时间】:2014-03-19 08:39:15
【问题描述】:

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

谢谢

【问题讨论】:

    标签: ios iphone objective-c gmail


    【解决方案1】:

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

    要实现 gmail,请使用带有 Gdata 标头的 libGDataTouchStaticLib.a 库(在 google 上搜索,否则将您的电子邮件发送给我,我会将其 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
        }
    
    
    }
    

    【讨论】:

      猜你喜欢
      • 2014-11-18
      • 2021-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-12
      • 1970-01-01
      • 2014-11-25
      • 2017-01-26
      相关资源
      最近更新 更多