Unable to monitor file upload progress on the iPhone

49 views
Skip to first unread message

Christoph Z.

unread,
Oct 30, 2009, 1:22:51 AM10/30/09
to Google Data APIs Objective-C Client Library Discussion
Hi Greg,

It seems the latest release contains a regression in that the upload
progress selector is never being called on the iPhone. I tried the
latest DocsSample on the desktop and that works fine. However, when I
compile the same code for the iPhone, the upload selector never gets
called. This used to work up to about 2-3 weeks ago when I tried the
latest top of the trunk sources. Any ideas?

- (void)uploadFileAtPath:(NSString *)path
{
SEL progressSel = @selector
(inputStream:hasDeliveredByteCount:ofTotalByteCount:);
[service setServiceUploadProgressSelector:progressSel];

self.ticket = [service fetchEntryByInsertingEntry:newEntry
forFeedURL:postURL delegate:self
didFinishSelector:@selector
(uploadFileTicket:finishedWithEntry:error:)];

self.ticket.isRetryEnabled = YES;
}

- (void)inputStream:(GDataProgressMonitorInputStream *)stream
hasDeliveredByteCount:(unsigned long long)numberOfBytesRead
ofTotalByteCount:(unsigned long long)dataLength
{
// Never gets called on the iPhone
}


Note: I also tried the following signature, just like the latest
DocsSample has it, but it doesn't get called:

- (void)ticket:(GDataServiceTicket *)ticket hasDeliveredByteCount:
(unsigned long long)numberOfBytesRead ofTotalByteCount:(unsigned long
long)dataLength
{
}


Thanks,
Christoph

Greg Robbins

unread,
Oct 30, 2009, 2:08:04 AM10/30/09
to gdata-objec...@googlegroups.com
The upload progress mechanism has changed since the 1.8 library to take advantage of better recent support in NSURLConnection, but the library's callback progress code has not changed in the last few weeks.

The first argument of the progress selector method is no longer an input stream; it's now the ticket. Be sure to update both your callback method and the call to setServiceUploadProgressSelector:.


Try setting a breakpoint in GDataServiceBase's fetchObjectWithURL: method.

Is the local boolean variable doesSupportSentData in that method being set?


Also try setting a breakpoint in GDataServiceBase's didSendBytes: and hasDeliveredBytes: methods.

Christoph Z.

unread,
Oct 30, 2009, 2:22:37 AM10/30/09
to Google Data APIs Objective-C Client Library Discussion
Hi Greg,

Thanks for the quick reply. It turns out that the upload progress
mechanism does not work on iPhone OS 2.2.1, but does work on OS 3.1.2
- tried exactly the same code on iPod Touch running 2.2.1 over Wi-Fi
and iPhone running 3.1.2. Sounds like it's related to the changes in
the NSURLConnection, but given 2.2.1 is becoming obsolete fairly
quickly - it's probably not even worth fixing.

Thanks,
Christoph

Greg Robbins

unread,
Oct 30, 2009, 2:28:30 AM10/30/09
to gdata-objec...@googlegroups.com
GDataHTTPFetcher is using NSFoundationVersionNumber to determine if the new callback mechanism is available:

+ (BOOL)doesSupportSentDataCallback {
  // per WebKit's MaxFoundationVersionWithoutdidSendBodyDataDelegate
  //
  // indicates if NSURLConnection will invoke the didSendBodyData: delegate
  // method
  return (NSFoundationVersionNumber > 677.21);
}

I'm curious if that logic is incorrect. What's NSFoundationVersionNumber on iPhone 2.2.1? Is didSendBodyData: in GDataHTTPFetcher being invoked on iPhone 2.2.1?

Greg Robbins

unread,
Oct 30, 2009, 2:37:50 AM10/30/09
to gdata-objec...@googlegroups.com
The NSFoundationVersionNumber list at http://tinyurl.com/ykamm6j indicates that, according to the WebKit logic, iPhone OS 2 should be invoking the didSendBodyData: callback method.

If that's not happening, I'll need to change the logic in GDataHTTPFetcher's
doesSupportSentDataCallback to avoid the new sent data callback method usage prior to iPhone OS 3.

Greg Robbins

unread,
Oct 30, 2009, 4:42:58 PM10/30/09
to gdata-objec...@googlegroups.com
To fix this, I'll probably update GDataHTTPFetcher by replacing doesSupportSentDataCallback with:

+ (BOOL)doesSupportSentDataCallback {
#if GDATA_IPHONE
  // NSURLConnection's didSendBodyData: delegate support appears to be
  // available starting in iPhone OS 3.0
  return (NSFoundationVersionNumber >= 678.47);
#else

  // per WebKit's MaxFoundationVersionWithoutdidSendBodyDataDelegate
  //
  // indicates if NSURLConnection will invoke the didSendBodyData: delegate
  // method
  return (NSFoundationVersionNumber > 677.21);
#endif
}

Christoph Z.

unread,
Oct 31, 2009, 3:27:42 AM10/31/09
to Google Data APIs Objective-C Client Library Discussion
Hi Greg,

I applied your suggested fix and now the upload progress mechanism
works great on both OS 3.1.2 and 2.2.1.

Thanks so much!
-Christoph

Greg Robbins

unread,
Nov 2, 2009, 3:23:43 PM11/2/09
to gdata-objec...@googlegroups.com
I have updated the release build of the library to version 1.9.1 with this change.

Developers who will be using the library to do file uploads on iPhone should use version 1.9.1 of the library. The change is unimportant for other developers; 1.9 is fine in other respects.

Reply all
Reply to author
Forward
0 new messages