Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
uploadPhoto to Google Contact
- (GDataEntryContact *)uploadPhotoWithContactService:(GDataServiceGoogleContact *)contactService contact:(GDataEntryContact *)targetContact photoData:(NSData *)photoData
{
GDataEntryBase *uploadPhotoEntry = [GDataEntryBase entry];
// file path on iOS don't need
NSString *mimeType = [GDataUtilities MIMETypeForFileAtPath:nil
defaultMIMEType:@"image/*"];
[uploadPhotoEntry setUploadMIMEType:mimeType];
[uploadPhotoEntry setUploadData:photoData];
// |setShouldUploadDataOnly| will only upload data without entry data
[uploadPhotoEntry setShouldUploadDataOnly:YES];
NSURL *postURL = [[targetContact photoLink] URL];
__block GDataEntryContact *newContactEntry = nil;
__block NSError *newError = nil;
[contactService fetchEntryByUpdatingEntry:uploadPhotoEntry forEntryURL:postURL completionHandler:^(GDataServiceTicket *ticket, GDataEntryBase *entry, NSError *error) {
newContactEntry = (GDataEntryContact *)entry;
newError = error;
}];
return newContactEntry;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment