簡體   English   中英

需要建議將gmail帳戶集成到iOS開發中

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

我是iOS編程的新手,只想做點有趣的事情。 我想為iPhone開發一個郵件客戶端應用程序,它可以添加電子郵件帳戶,例如gmail和Yahoo等。 我在網上搜索了一段時間,也找到了一些答案 ,然后再深入研究細節,我只希望有類似經驗的人給我一些關於哪種方法最好的建議。

謝謝

我最近實現了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
    }


}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM