可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I implement access to Google Drive in my iOS app. This has been an active feature in the app since middle of 2014 and functions properly under iOS 6, 7 & 8. I am currently checking my project for compatibility with iOS 9.
I've downloaded the latest google-api-objectivec-client
to ensure my project remains up to date.
I redid the standard Google implementation... as detailed in this page and included for completeness at the end of this post.
Problem: When I attempt to build in any of my releases I receive the error "GTMSessionFetcher.h
file not found".
I'm certain I've implemented the API properly as per the steps below / on the Google web page.
I've looked through older versions of my code but unfortunately I did not back up the Google SDK, so cannot easily tell what has changed.
It seems to stem from this... within GTMOAuth2Authentication.h
...
#if GTM_USE_SESSION_FETCHER #import "GTMSessionFetcher.h" #else #import "GTMHTTPFetcher.h" #endif // GTM_USE_SESSION_FETCHER
I dont understand how GTM_USE_SESSION_FETCHER
is set and why it would be true in this instance.
Any advice greatly appreciated.
Google Drive API Implementation for iOS
Note: Steps 1 & 2 complete without issue.
Step 3: Prepare the project
- In Xcode, create a new project to contain the sample app:
- Click File > New > Project, select the Single View Application template, and click Next.
- Fill in the Product Name, Organization Name, and Company Identifier. Make sure to select Objective-C as the Language, and then click Next.
- Select a destination directory for the project and click Create.
- Add the client library by dragging
GTL.xcodeproj
from the Source
directory of the client library download folder above into the XCode project. - In the XCode Project Navigator, select the project you created to reveal the project settings.
- Select the Build Phases tab in the project settings and modify the
Link Binary with Libraries
list to include: libGTLTouchStaticLib.a
from the GTL project. Security.framework
and SystemConfiguration.framework
.
- Select the Build Settings tab in the project settings and modify the following two build settings:
- Add
-ObjC -all_load
to the Linking > Other Linker Flags setting. A good way to edit these fields is to click once on the field name to select it, then click Enter to input the setting. - Add the client library headers to the application project by adding the Source directory of the client library to the Search Paths > User headers search path section with the recursive option. You can select the recursive option either by appending ** to the path or by double-clicking the entered path and selecting recursive in the dialog that appears. To find the absolute path to this directory in a Unix-based system, navigate a terminal window to the directory where you downloaded the client library in Step 2, cd into the Source directory, and type the pwd command.
- Drag
GTMOAuth2ViewTouch.xib
from client library's Source/OAuth2/Touch
folder into the app's Supporting Files
folder. - Add the Drive API service by dragging
GTLDrive.h
and GTLDrive_Sources.m
from the client library's Source/Services/Drive/Generated
folder directly to the application project.
回答1:
Thanks initially to Rivero for pointing me in the right direction...
Thanks to Peter for his answers to this question.
Building for iOS 6, 7, 8 & 9...
Hacked the following...
STEP 1
In GTMOAuth2Authentication.h
(OAuth directory) and in GTLService.h
(Objects directory)
find this code block...
#if (!TARGET_OS_IPHONE && defined(MAC_OS_X_VERSION_10_11) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_11) \ || (TARGET_OS_IPHONE && defined(__IPHONE_9_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_9_0) #ifndef GTM_USE_SESSION_FETCHER #define GTM_USE_SESSION_FETCHER 1 #endif #endif
... and change
#define GTM_USE_SESSION_FETCHER 1
... to
#define GTM_USE_SESSION_FETCHER 0
STEP 2
In GTMGatherInputStream.m
(HTTPFetcher directory)
... change
return [[[self alloc] initWithArray:dataArray] autorelease];
... to
return [[(GTMGatherInputStream*)[self alloc] initWithArray:dataArray] autorelease];
STEP 3
In GTMHTTPFetcherLogging.m
(HTTPFetcher directory)
... change
NSString *escapedResponseFile = [responseDataFileName stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
... to
NSString *escapedResponseFile = [responseDataFileName stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
STEP 4
In GTL
project settings, under Apple LLVM 7.0 Warnings - All Languages
... change
Deprecated Functions = YES
... to
Deprecated Functions = NO
回答2:
@andrewbuilder's solution works.
If your target is IOS 8, just change
#define GTM_USE_SESSION_FETCHER 1
to
#define GTM_USE_SESSION_FETCHER 0
in both GTMOAuth2Authentication.h and GTLService.h files.
If your target is IOS 9, you need to replace the GTMHTTPFetcher file with GTMSessionFetcher file (https://code.google.com/p/gtm-session-fetcher/).
Reference: https://github.com/google/google-api-objectivec-client/issues/88
回答3:
Google APIs Client Library for Objective-C using JSON-RFC has been replaced with REST (no end date released yet).
Pulling the new library with all dependencies worked for me with no hacking what so ever.
https://github.com/google/google-api-objectivec-client
git clone --recursive https://github.com/google/google-api-objectivec-client-for-rest.git
回答4:
I was also facing the same issue.This is the way how I managed to solve this.
Documentation says that we should put absolute path in User Header Search Paths.I was putting absolute path but my directory name contained spaces which was not understood correctly by Xcode.My Directory was
/Users/maclover/Xcode Test Projects/Manager/gtm-session-fetcher/Source/
Then I changed to directory which didnot contain any spaces like
/Users/maclover/Desktop/Manager/gtm-session-fetcher/Source/
Changing this in User Header Search Paths in my application and GTLTouchStaticLib worked for me.Do same for objective C client path as well.
Last thing there is no need for #define GTM_USE_SESSION_FETCHER 1
changed to #define GTM_USE_SESSION_FETCHER 0
if you are using latest projects.It was workaround for previous library and google has updated it now on November 10.
回答5:
After numerous trials and errors, i stumbled upon a forum post saying that Google has been focusing its efforts on the pod version of the API client.
Use:
pod 'GoogleAPIClient'
link source: GoogleApiClient
回答6:
STEP 1
GTMOAuth2Authentication.h
#define GTM_USE_SESSION_FETCHER 1 to #define GTM_USE_SESSION_FETCHER 0
STEP 2
GTMGatherInputStream.m
return [[[self alloc] initWithArray:dataArray] autorelease]; ... to return [[(GTMGatherInputStream*)[self alloc] initWithArray:dataArray] autorelease];
STEP 3 like image: ios version choose less than ios 9
STEP 4 enable bitCode