Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
- (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;
}