samjee / google-api-objectivec-client

Automatically exported from code.google.com/p/google-api-objectivec-client
0 stars 0 forks source link

GTLServiceDrive's -executeQuery:completionHandler: never calls completion handler if in airplane mode #57

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. Set iPhone to Airplane Mode (in Settings App)

2. Start my app, which executes the following code:
    // In cAppDelegate's application:didFinishLaunchingWithOptions:
    [GMSServices provideAPIKey:@"myAPIKeyHere"];

3. Tap an upload button to upload a file to Google Drive, which executes these:
    // Load Google authentication from keychain.
    GTMOAuth2Authentication* googleAuthentication = [GTMOAuth2ViewControllerTouch authForGoogleFromKeychainForName:@"KeychainNameForGoogleHere" clientID:@"myClientID" clientSecret:@"myClientSecret"];
    // googleAuthentication.canAuthorize is YES after this line. My Google account authentication was saved in keychain beforehand.

    // Init Google Drive service.
    GTLServiceDrive* googleDriveService = [[GTLServiceDrive alloc] init];
    googleDriveService.authorizer = googleAuthentication;

    // Upload to Google Drive.
    GTLDriveFile* googleDriveFile = [GTLDriveFile object];
    googleDriveFile.title = @"FileTitle";
    googleDriveFile.mimeType = @"MimeType";

    GTLUploadParameters* uploadParameters = [GTLUploadParameters uploadParametersWithData:FileData MIMEType:googleDriveFile.mimeType];  // FileData is the pre-filled file data.
    GTLQueryDrive* queryDrive = [GTLQueryDrive queryForFilesInsertWithObject:googleDriveFile uploadParameters:uploadParameters];

    GTLServiceTicket* serviceTicket = [googleDriveService executeQuery:queryDrive completionHandler:^(GTLServiceTicket *ticket, GTLDriveFile *insertedFile, NSError *error) {
        // If failed...
        if(error)
        {
            // Handle error.
            return;
        }

        // Handle success.
    }];
    if(!serviceTicket)
    {
        return; // This line is not executed. I checked with the debugger and serviceTicket is indeed not nil.
    }

    [serviceTicket setUploadProgressBlock:^(GTLServiceTicket *ticket, unsigned long long totalBytesWritten, unsigned long long totalBytesExpectedToWrite) {
        // Handle progress.
    }];

4. Both the progress block and the completion handler is never called.

The interesting thing is that, if I now turn off Airplane mode, go back to my 
app, and tap the upload button again, it uploads successfully. And if I now 
turn on Airplane mode once again, go back to my app, and tap the upload button 
again, this time, it will call the completion handler with an NSError saying 
"The Internet connection appears to be offline.".

--------------------------------------------------------------------------------
----------------------------------------

What is the expected output? What do you see instead?

I expect the completion handler to be called when my phone is in Airplane mode.

--------------------------------------------------------------------------------
----------------------------------------

What version of the product are you using? On what operating system?

- Xcode 5.0.2 + Mac OS X 10.9.1
- iPhone 5 + iOS 7.0.4
- Google APIs Client Library for Objective-C, revision 379, from 
http://code.google.com/p/google-api-objectivec-client/

--------------------------------------------------------------------------------
----------------------------------------

Please provide any additional information below.

I also tried enabling logging, as instructed here:
http://code.google.com/p/google-api-objectivec-client/wiki/Introduction#Logging_
HTTP_Server_Traffic
but the line [GTMHTTPFetcher setLoggingEnabled:YES] won't compile.

I then added STRIP_GTM_FETCH_LOGGING=0 to my project setting but it won't 
compile either.

I changed it to STRIP_GTM_FETCH_LOGGING=1 and then it compiles, but I don't 
know where the log went. Anyway, STRIP_GTM_FETCH_LOGGING=1 doesn't seem to make 
sense here, but the line "+ (void)setLoggingEnabled:(BOOL)flag;" in 
GTMHTTPFetcher.h is surrounded by #if STRIP_GTM_FETCH_LOGGING, so I don't know.

Original issue reported on code.google.com by forcodep...@gmail.com on 1 Jan 2014 at 10:05

GoogleCodeExporter commented 9 years ago
Oops. Sorry. That "[GMSServices provideAPIKey:@"myAPIKeyHere"];" line was 
unrelated.

Anyway, I've put up a sample project that can reproduce the exact problem (see 
attachment).

The project is created like this:
* In Xcode, create new project (File -> New -> Project -> Single View 
Application).
* Checkout Google APIs Client Library for Objective-C, with this command:
    svn checkout http://google-api-objectivec-client.googlecode.com/svn/trunk/ google-api-objectivec-client-read-only
* Configure Xcode project to add Google library to project.
* Add buttons in storyboard, and add corresponding code.

Original comment by forcodep...@gmail.com on 4 Jan 2014 at 3:36

Attachments: