Adding Google Objective-C API 'GTL' to iPhone project - objective-c

How to I add the Google Drive API to my iPhone project to I can use it?
So far, I have dragged the GTL project into my current app project (so that it is nested under my app project). Then, under my app target's build phases, I added GTL.framework, and then added GTL.framework to my 'Link binary with Libraries' (see attached pic). This throws the following error:
clang: error: no such file or directory: '/Users/xxx/Library/Developer/Xcode/DerivedData/Golf-hfbczyaemhyzgvbrtgdxqnlzeuaa/Build/Products/Debug-iphonesimulator/GTL/GTL'
How to I fix this?

I struggled with this exact issue for most of the day today, and I found it extremely frustrating. I have finally figured it all out so here is a straightforward step by step guide on how to add the Google API to an iOS7 project using XCode5, using ARC, without having to create Workspaces or any of that.
The answer provided by RawMean works well, but it gave me issues with ARC. I also didn't like the fact that you had to add project, create a workspace and then delete the project. So my solution will deal with both these issues.
Check out the code. To do this, you can just run svn checkout http://google-api-objectivec-client.googlecode.com/svn/trunk/ google-api-objectivec-client-read-only from your terminal. I will refer to this code as "Google's code".
Go to your project's Build Phases. Expand "Link Binary With Libraries" and add Security.framework and SystemConfiguration.framework. These two are required by Google's code.
Go to your project's Build Settings. Using the search box there, look for Other Linker Flags (make sure "All" is selected to the left of the search box). Add -ObjC -all_load.
Now search for User headers search path and add the full path to Goggle's /Source directory. Make sure you select recursive.
Using Finder, go to Google's /Source/OAuth2/Touch directory. Drag and drop GTMOAuth2ViewTouch.xib into your project.
Go back to Finder and go to Google's /Source directory. Drag and drop GTLCommon_Sources.m and GTLCommon_Networking.m into your project.
Now, you need to import the files for the services you want to use. In my case, I need to use Google Drive, so I'll add those. In finder, go to Google's /Source/Services/Drive/Generated directory. Drag and drop GTLDrive.h and GTLDrive_Sources.m into your project. If you want to use other services, go to their directory and import the appropriate .h and .m file.
For some reason, Google's code doesn't use ARC, so if you try to build right now, you will get ARC compile errors. So we need to disable ARC for Google's code only. To do this, go back to your project's Build Phases, but this time expand "Compile Sources". Make sure that GTLCommon_Sources.m and GTLCommon_Networking.m are there. Select them, press enter and type in -fno-objc-arc. This will disable ARC for both of them. Make sure you don't add this option for any other file (unless you know what you're doing).
You are done! Now, whenever you want to use Google's API, just import GTMOAuth2ViewControllerTouch.h and your service header. In my case, since I'm using Google Drive, I will also import GTLDrive.h.
I hope that helps and saves some people from pulling all their hair out.

I struggled with this error message as well. This is how I solved it:
Make sure you have added the folder for the service that you are using under GTLSource/Common/ (e.g., add the Drive folder for GoogleDrive).
Under GTL.xcodeproj (that you have already added to your workspace) find the GTLSource folder and drag it to your main project (Golf in your case). Done!
Now you can remove references to the GTL.xcodeproj that you have added to the workspace.
With this approach, you don't even need to add the libraries (so remove them from the list of linked libraries if you have added them).
The Google API documentation is nothing like Apple's documentation (it's not good).
I should also mention that I'm building an app for iOS and not MacOSX, but this should work for OSX as well.

Not only doing the above, but go under "[Project Name] Targets->Build Phases> Compile Sources" and click the + button. Then add all the .m files, for some reason most of the aren't automatically.
I also had to delete (the reference) to "GTLDrive_Souces.m" from the Drive folder, but I don't understand why i had to do that part.

Better to use Pod
How to install CocoaPods and setup with your Xcode project
for reference : [http://blogs.triffort.com/?p=309][1]
Open the pod file and add
pod 'Google-API-Client/Drive', '~> 1.0' save pod file and call pod install in terminal. Note:pod file you must give link_with
'Your_project_name', 'Your_project_nameTests' after this line only add
your library

this is does not really solve the problem of installing Google API's but in this repo I accessed Google Forms from an iOS app without using Google's API. https://github.com/goktugyil/QorumLogs
So you may skip the installing API part in some projects
Here is the tutorial of how to set it up:
https://github.com/goktugyil/QorumLogs/blob/master/Log%20To%20GoogleDocs.md
Heres the code to do it:
private static var googleFormLink: String!
private static var googleFormAppVersionField: String!
private static var googleFormUserInfoField: String!
private static var googleFormMethodInfoField: String!
private static var googleFormErrorTextField: String!
/// Setup Google Form links
static func setupOnlineLogs(#formLink: String, versionField: String, userInfoField: String, methodInfoField: String, textField: String) {
googleFormLink = formLink
googleFormAppVersionField = versionField
googleFormUserInfoField = userInfoField
googleFormMethodInfoField = methodInfoField
googleFormErrorTextField = textField
}
private static func sendError(#text: String) {
var url = NSURL(string: googleFormLink)
var postData = googleFormAppVersionField + "=" + text
postData += "&" + googleFormUserInfoField + "=" + "anothertext"
postData += "&" + googleFormMethodInfoField + "=" + "anothertext"
postData += "&" + googleFormErrorTextField + "=" + "anothertext"
var request = NSMutableURLRequest(URL: url!)
request.HTTPMethod = "POST"
request.setValue("application/x-www-form-urlencoded; charset=utf-8", forHTTPHeaderField: "Content-Type")
request.HTTPBody = postData.dataUsingEncoding(NSUTF8StringEncoding)
var connection = NSURLConnection(request: request, delegate: nil, startImmediately: true)
}

Related

How to add a custom library to a scratch file

In PhpStorm/WebStorm how can I add a custom library so that the file compiles? In my case it would be Lodash?
I tried to add lodash to global libs but it did not help...
Using require and relative paths.
Here is a crazy example of using lodash in a scratch file:
const _ = require('./../../../DEV/node_modules/lodash');
var anything = [1, 2];
_.map(anything, function (item) {
console.log('Working >-P');
return item;
});
In fact, you can just add a package.json file to your scratches.
You could create one manually, but the following may be more practical:
Right click on any of your scratch files, then select "Open in terminal".
You'll notice that it will open the terminal directly in the folder of the scratches.
That's a folder such as C:\Users\ba\AppData\Roaming\JetBrains\WebStorm2020.2\scratches.
Since you are in the correct directory now, you can just run npm init from that terminal to create your package.json file. (You will be prompted with a bunch of questions, but you can just press enter for all questions if you are fine with the default values)
This file will just show up in your scratches along with your other files.
To answer your specific question, if you want to add lodash to those packages, you can open the terminal in the way mentioned above. This terminal will be in the correct folder. And then you can just run your npm install lodash from there.
var path = require('path');
_require = require;
require = function (p) {
var absPath = path.join(process.cwd(), p);
var relPath = path.relative(__dirname, absPath);
return _require(relPath);
}
var Query = require('./server/libs/query_builder.js');
A bit late to answer, but if you replace the require function as I show above you can use it normally.
Well I would suggest in this case to use plugin named Quokka.js available for Webstorm and other JetBrains tools.
It's recognise automatically the libraries from node_modules and have a lot of other features (work much better that pure scratch files).
When you will install it the default scratch Javascript and Typescript files will work with Quokka.
You will find the details on the official tool page: https://quokkajs.com/
Please select JET BRAINS tool on main page. Hope it helps.

Xcode cannot find ProductModuleName-Swift.h

I'm attempting to import my "-Swift.h" file into one of my Objective-C .h files but xcode keeps telling me that the file doesn't exist
#import "Aesculus-Swift.h"
If I command click on the file name it will take me to the generated header file so I know it exists. Why is xcode not able to find it?
This seems like just another issue with Xcode and it's complex tool chain of static analysers and compilers.
Openradar lists radar://21362856 - Swift to Objective-C bridging is unreliable. I am sure there are more but I stopped looking after finding one for this example.
The author imarcelv notes in the description:
I asked a Swift engineer at WWDC in a lab and even he didn't know how to fix this issue.
Steps to Reproduce:
Add a ramdom Swift class to an Objective-C project
Add the #import "ModuleName-Swift.h" file that Xcode generates automatically
Try to use it or just try to compile the project
From time to time it simply doesn't work
It's probably best to file a radar on this issue as it seems that others are already calling it out.
One other thing you could try...
Historically, it was possible for Xcode to completely lose it's syntax highlighting and you could always find out what files the static analyser was giving up on by increasing log level of clang.
I'm not sure if it's still relevant but if I was in your position I'd be trying this command:
defaults write com.apple.dt.Xcode IDEIndexingClangInvocationLogLevel 3
This generates logs you can search with using Console.app for just xcode to highlight the messages. You'll want to trash the derived data of your project to force it to re-compile things.
Although not the same issue as what you're seeing, I have had this post on the syntax highlighting issue bookmarked for years for the above defaults write command to try in times like these.
I solved this recently by adding the following entry to my .xcconfig (you could add it in Xcode's Build Settings > User Header Search Paths if you prefer).
USER_HEADER_SEARCH_PATHS = $(BUILT_PRODUCTS_DIR)/MyFramework.framework/Headers
This tells the compiler to search for headers in the build output directory, which is where Xcode puts the generated header (at least in the case of this framework).
In my case this is a directory like ~/Library/Developer/Xcode/DerivedData/MyProject-LongCode/Build/Products/Debug-iphonesimulator/MyFramework.framework/Headers/MyFramework. You might find your generated header in there too.
Xcode's header and dependency management is a hot mess, and it's not surprising that it doesn't work for you.
I had trouble with this stuff & found that your -Swift file is the Product name of your Target ( not just the name of your Target ) . I found the details here helpful: http://ericasadun.com/2014/08/21/swift-calling-swift-functions-from-objective-c/
When you encounter such situation, just find your kinda "ProductName-Swift.h" file by just cmnd+click on it (even if xcode shows warning about it is not found, the #import "Aesculus-Swift.h" string is still clickable) and then in opened code editor window choose context menu and "Show in Finder" item, then explicitly add it to your project.

Play framework 2.1 can't use custom modules

I'm not able to use a module which I created by myself. I do everything like the following description:
http://java.dzone.com/articles/writing-modules-play-2-get
But there are little changes which shouldn't have any influence of the functionality: I don't change the project-struktur and i create separates projects in different folders. I think I should describe my steps for using and creating my own module and perhaps anyone see my mistake:
I create one project with play new testapp (workspace/testapp). Then i create an other projekt with play new testmodul (workspace/testmodul). Then i go to the testmodul and delete the route-file and the content of the application.conf. Then i create a class called "Tester" with the method test. (a simple system.out) After that i exceute "clean", "compile" and "publish-local" in the testmodul-folder.
In my understanding the modul ist published in the local repository of play and every application which want to use this module will have access to the local repository version of the module.
Now I go to the testapp and create the dependencies in the Build.scala. After that i go to the default-Application.class and add the line "Tester.test();". Then I excecute the dependencies command and try to compile.
After that i get the error, "can't find symbol". It seemed to be that the testapp don't know the Tester.class and that means that the testapp don't know the module.
But I don't know why.
Has anybody an idea?
Edit:
Perhaps I should display my dependencie config of the testapp:
val appDependencies = Seq(
// Add your project dependencies here,
javaCore
,javaJdbc
,javaEbean
,"testmodul" % "testmodul_2.10" % "1.0-SNAPSHOT"
)
val main = play.Project(appName, appVersion, appDependencies).settings(
// Add your own project settings here
resolvers += "Local Play Repository" at "file://C:/play-2.1.0/repository/local"
)
I'm not sure why the solution above wasn't right, but i found a solution. I found out that in the documentation of the playframework "modules" called "subprojects" there I found how to include modules. (http://www.playframework.com/documentation/2.1.0/SBTSubProjects)
But I think the other way of "global" modules should also be possible.
Change this line
resolvers += "Local Play Repository" at "file://C:/play-2.1.0/repository/local"
To
resolvers += "Local Play Repository" at "file://play-2.1.0/repository/local"
Just remove the C:/ .It worked for me. Check this http://www.objectify.be/wordpress/?p=363.

Clearing .png files from a Xcode project

In my Xcode project, i added a bunch of images to use. I need to change out the images so i removed them from the project and deleted them from the folder structure. They should be gone, right?
No. when i launch the program, the images are still being used. I did a search on my computer for the file name and only found it in the code
(i used a constants file and put the file names into strings:
NSString * const PRESET_LIGHT_GRAY = #"preset-rect-16.png";
NSString * const PRESET_ASH_GRAY = #"preset-rect-17.png";
and this is the only place on my mac that i find the file name).
there is no file on my mac named "preset-rect-16.png" yet Xcode is still using the image.
where is Xcode getting the images? are they stored somewhere else in the project? are they saved in the simulator somewhere?
/puzzled
Go here. Xcode -> Preferences -> Locations -> Derived Data
Wherever your Derived Data Folder is, delete Build for this Project and then run again. Resetting the Simulator is also recommended.
The images may still be referenced in your target build phases under copy bundle resources. If so delete the references there as well.

import "cocos2d.h" works in some files, but not all

Here is what I did:
In Xcode 4.3.1
File -> New -> Project -> Single view application
Dragged the file cocos2d-ios.xcodeproj into navigator.
In build phases settings : Added : libcocos2d.a (becomes highlighted in red), as a linked library (required).
Added OpenGles.framework, Quartzcore, and libz.dylib
Changed build settings - Set "Always Search User Paths" to YES
Added cocos2d source directory to "User Header Search Paths"
Now, it seems I can type: import "cocos2d.h" , in the app delegate and root view controller that Xcode created. But if I create a new file, and I add the line "import "cocos2d.h"" to the top, Xcode complains that the file is not found. But it seems to build fine. Also, in this new file code sense does not work.
What should I do? Why can I import only in the files that Xcode created? Is there some setting I need to change so that in the files I create, I can import cocos2d ?
EDIT: It seems to build and run fine. I can call methods in the cocos2d api. code sense just doesn't seem to see cocos2d.h in the new files I create.
EDIT - it seems that code sense suggests cocos2d.h when i type : import "
But it does not suggest classes / methods from the cocos2d api.
Turns out I had only added the "user header search paths" to my target, but not in the project settings.
Adding it fixed the problem. I guess the reason it compiled fine was because I had added it to the target, but it didn't work in the text editor since I hadn't added it to the project.
This happened to me as well, even though I did add it to both project and target.
However, what worked for me was to select the RECURSIVE checkbox under "User Header Search Prefixes" (which was set to "/lib/**")
I had same issue.
My project -> Build Settings
Look for the entry for Search Paths
Always Search User Paths - YES
User Header Search paths - "myProjectName/libs" //I put box2d folder here
Hope this help someone.