Skip to content

Instantly share code, notes, and snippets.

@Superbil
Created December 22, 2011 05:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Superbil/1508976 to your computer and use it in GitHub Desktop.
Save Superbil/1508976 to your computer and use it in GitHub Desktop.
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