iOs: Swift Google Analytics - ios

I am new to iOs development and would like to implement Google Analytics (swift).
It appears there is some missing information on implementing Google Analytics in swift on Google's instruction page:
It seems the import statement above is incorrect, can anyone assist me with the missing/correct statement?
Exta Info:
I come from a Java background and IDEs I use import for you, so
please excuse my stupidity.
I have cocopods installed, and use other pods: Almofire, Fabric, swiftyJson etc
I am developing for iOs 8
Instructions above this, are clear and working. Installing the pods/config file etc

In your Objective-C bridging header file, You should import GA header files:
#import "GAI.h"
#import "GAIDictionaryBuilder.h"
#import "GAIEcommerceFields.h"
#import "GAIEcommerceProduct.h"
#import "GAIEcommerceProductAction.h"
#import "GAIEcommercePromotion.h"
#import "GAIFields.h"
#import "GAILogger.h"
#import "GAITrackedViewController.h"
#import "GAITracker.h"
I am not sure if I am missing some import.

If you look in your Pods folder in Xcode you can see the available pods there. Most of them usually have a file that contains all import statements for any files needed. In this case its the Analytics.h file in Pods/Google/Analytics/
I'm guessing that, to import this file in your bridging header (which I hope you have, if not let me know), you can use #import "Google/Analytics.h".
It also says a little bit lower on the page, to import the <Google/Analytics.h> to the header.

Related

Xcode generated umbrella header for framework does not import Foundation when #objc inference is turned off

I have a framework written entirely in Swift, and it's included in an app that uses a mix of Objective-C and Swift, i.e.
#import "MyFramework-Swift.h"
If Swift 3 #objc inference is turned ON for the framework target then everything compiles and runs fine. If Swift 3 #objc inference is turned OFF then the framework itself will compile, but the file that it's included in does not and spits out a bunch of errors like:
Unknown type name 'NSArray' or Unknown type name 'NSError'
The imports in the Objective-C file where I'm trying to use this framework essentially look like this (i.e. Foundation is being imported before trying to import the swift framework):
#import Foundation;
#import <OtherNonSystemHeaders.h>
#import "ThisFilesHeader.h"
#import "MyFramework-Swift.h"
If I open up the header file that Xcode generates there's a section about 150 lines down that looks like this:
#if __has_feature(modules)
#import ObjectiveC;
#endif
And if I manually change it to this it will compile and run.
#if __has_feature(modules)
#import ObjectiveC;
#import Foundation;
#endif
Obviously that's not a real solution since it gets overwritten any time Xcode regenerates that header, but I can't understand why turning off #objc inference is causing that import to disappear. I have manually marked certain methods as #objc, all the classes in the framework subclass NSObject, and each file imports Foundation.
I thought this might be a bug, but this happens both with Xcode 9.2 and 9.3, and clearly people are able to turn off #objc inference since it's now a recommended setting. But I am truly at a loss.
This sounds like you're missing #import Foundation; in your ObjC prior to:
#import "MyFramework-Swift.h"
ObjC files should #import Foundation; themselves. This is often also placed in the precompiled header (.pch) for performance reasons, but each .m should still import everything it needs, including Foundation.
Typically I recommend the following layout for .m files:
#import ...System Headers...
#import "Non-system framework headers"
#import "Local headers"
#import "Project-Swift.h"
We recently had to workaround what sounds like the same problem, although for us #objc inference didn't make a difference. Here is what we did:
In the MyFramework project, add a top-level header file MyFramework.h with just this one-liner:
#import Foundation;
Make sure that this file is added to each of the targets in your framework project as a Public header (not Private or Project... this part is important).
Rebuild the framework. The generated MyFramework-Swift.h still won't #import Foundation but you will see the new MyFramework.h file right beside it in the built framework's Headers folder.
Import your framework into your app's Objective-C files using the same #import <MyFramework/MyFramework-Swift.h> syntax you're probably already using. You should no longer receive the Unknown type name errors.

GoogleAnalytics Cocoapod unresolved identifier 'GGLContext'

With the Google cocoapod now deprecated I have switched to using the GoogleAnalytics pod and amended my bridging header to import the following:
#import "GAI.h"
#import "GAIDictionaryBuilder.h"
#import "GAIEcommerceFields.h"
#import "GAIEcommerceProduct.h"
#import "GAIEcommerceProductAction.h"
#import "GAIEcommercePromotion.h"
#import "GAIFields.h"
#import "GAILogger.h"
#import "GAITrackedViewController.h"
#import "GAITracker.h"
Now my build keeps failing at:
GGLContext.sharedInstance().configureWithError(&configureError)
Can't find anything in the Google docs and Google searches have also proved fruitless.
A point in the right direction would be greatly appreciated, or even pointing out something painfully obvious that I'm missing.
This answer was the correct one, not the one marked as "correct" since it suggests to use deprecated version of libraries instead of moving on with the new versions and updating your project accordingly:
https://stackoverflow.com/a/46858690/3506788
If you use Firebase, make sure that you initialise Firebase before using this line:
GIDSignIn.sharedInstance().clientID = FirebaseApp.app()?.options.clientID

Swift + Objective C Venmo Pod: 'VENUser.h' file not found

I'm trying to integrate this in a Swift application. I'm using Xcode 6.4 and CocoaPods 0.38.2.
My podfile looks like this:
platform :ios, '8.0'
use_frameworks!
target 'my_app_name' do
pod 'Venmo-iOS-SDK', '~>1.3'
end
With no import in my bridge header, the app runs. With #import <Venmo_iOS_SDK/Venmo.h> however, I get the following error:
..Pods/Venmo-iOS-SDK/venmo-sdk/Categories/VENUser+VenmoSDK.h:1:9: 'VENUser.h' file not found
.../my_app_name-Bridging-Header.h:6:9: Could not build module 'Venmo_iOS_SDK'
Failed to import bridging header '../my_app_name/my_app_name-Bridging-Header.h'
The lines at the top of the Venmo.h file are as follows
#import Foundation;
#import UIKit;
#import <VENCore/VENCore.h>
#import "VENErrors.h"
#import "VENPermissionConstants.h"
#import "VENSession.h"
#import "VENTransaction+VenmoSDK.h"
I tried adding another pod just to make sure it was an issue specifically with my integration with venmo-ios-sdk and ended up adding #import <VENCore/VENcore.h> with zero problems. I'm pretty new to iOS, so I don't really know if I'm missing something extra obvious...
You shouldn't be importing the framework within your bridge header, but instead importing it directly in your Swift code using Swift imports:
import Venmo_iOS_SDK
Alternatively if you are using the Pod from Objective-C, you should be importing the framework header:
#import <Venmo_iOS_SDK/Venmo_iOS_SDK.h>
Or, using module imports in Objective-C (http://tonyarnold.com/2014/04/10/clean-up-your-projects-with-xcode-5.html):
#import Venmo_iOS_SDK;
I don't know if there was another way to solve this, but I just edited the pod so in VEnUser+VenmoSDK.h the first line was changed to
#import "VENCore/VENUser.h"
instead of
#import "VENUser.h"
I was looking at the wrong file so didn't see the "obvious" error, nor was it particularly obvious to me...but this fixes it.
You can check Header search paths or Library search paths.
Also can pod install.

Stripe.h file not found in xcode

I am trying to use the Stripe SDK in my iOS App but there seems to be a problem. Whenever I try to import it like this:
#import "Stripe.h"
I get the following error:
Stripe.h file not found
But I have the file as shown in the picture attached.
Since Stripe is a framework, you need to import like this.
#import <Stripe/Stripe.h>
In your Objective-C –> Swift Bridging Header you have to import the Objective-C file like the following:
#import "Stripe.h"
Hope that helps :)

PFFacebookUtils.h (1.7.1) imports non-existent FacebookSDK.h

I've installed the Parse and Facebook iOS SDKs for my project in Xcode. My project is written in Swift so I have the following in my bridging header:
#import <Parse/Parse.h>
#import <ParseUI/ParseUI.h>
#import <ParseCrashReporting/ParseCrashReporting.h>
#import <Intercom/Intercom.h>
#import <ParseFacebookUtils/PFFacebookUtils.h>
When I build the app, I get 2 errors:
error: 'FacebookSDK/FacebookSDK.h' file not found
error: failed to import bridging header '/Users/ben/AppFolder/MyApp/Bridging-Header.h'
The bridging header is at the directory as shown, so it seems that is dependent on the first error. FacebookSDK.h is in an #import statement at the top of PFFacebookUtils.h:
#import <Foundation/Foundation.h>
#import <FacebookSDK/FacebookSDK.h>
#import <Parse/PFConstants.h>
#import <Parse/PFNullability.h>
#import <Parse/PFUser.h>
FacebookSDK.h does not exist in either the Parse iOS SDK 1.7.1 or the Facebook SDK (presumably 4.0.1) from Facebook's Getting Started page, though I know that FacebookSDK.h was in previous versions.
I tried the approved answer from this SO question without success. Do I need to add something to my bridging header? Should I change the import statement for FacebookSDK.h to reference a different file? Other ideas on how to fix this?
Instead of
#import <ParseFacebookUtils/PFFacebookUtils.h>
use :
#import <ParseFacebookUtilsV4/PFFacebookUtils.h>
Make sure to add that V4

Resources