0
我是iOS編程新手,只想做些有趣的事情。 我想開發一個iPhone的郵件客戶端應用程序,它可以添加電子郵件帳戶,如Gmail和雅虎等。我在網上搜索了一段時間,也發現了一些answers,在我深入細節之前,我只希望有相似經歷的人給我一些關於哪種方法最好的建議。需要在iOS開發中集成Gmail賬戶的建議
感謝
我是iOS編程新手,只想做些有趣的事情。 我想開發一個iPhone的郵件客戶端應用程序,它可以添加電子郵件帳戶,如Gmail和雅虎等。我在網上搜索了一段時間,也發現了一些answers,在我深入細節之前,我只希望有相似經歷的人給我一些關於哪種方法最好的建議。需要在iOS開發中集成Gmail賬戶的建議
感謝
我最近實施的Gmail API來獲取Gmail聯繫人和他們在我的tableview電子郵件。 Gmail api被刪除,這就是爲什麼你可能沒有任何適當的文件。
要實現gmail使用libGDataTouchStaticLib.a圖書館,與Gdata標題(谷歌搜索,否則發送給我你的電子郵件,我會給你它的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
}
}
非常感謝你! – photosynthesis