I'm pretty new to iOS and 100% new to AWS. I'm building an app that needs to upload files. I downloaded the Amazon SDK through CocoaPods and used a bridging header to work with it in Swift.
Here's my header:
#ifndef ObjC_Bridging_Header_h
#define ObjC_Bridging_Header_h
#import "AWSCore.h"
#import "AWSS3.h"
#import "AWSDynamoDB.h"
#import "AWSSQS.h"
#import "AWSSNS.h"
#import "AWSCognito.h"
#endif /* ObjC_Bridging_Header_h */
I pointed to that file in my build settings to tell the compiler where it was.
Then I tried to configure the SDK in my AppDelegate.swift with this code:
var window: UIWindow?
let cognitoAccountId = "I'm not going to post this"
let cognitoIdentityPoolId = "I'm not going to post this"
let cognitoUnauthRoleArn = "I'm not going to post this"
let cognitoAuthRoleArn = "I'm not going to post this"
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let credentialsProvider = AWSCognitoCredentialsProvider.credentialsWithRegionType(
AWSRegionType.USEast1,
accountId: cognitoAccountId,
identityPoolId: cognitoIdentityPoolId,
unauthRoleArn: cognitoUnauthRoleArn,
authRoleArn: cognitoAuthRoleArn)
let defaultServiceConfiguration = AWSServiceConfiguration(
region: AWSRegionType.USEast1,
credentialsProvider: credentialsProvider)
AWSServiceManager.defaultServiceManager().setDefaultServiceConfiguration(defaultServiceConfiguration)
return true
}
(And yes, I put in all of the ID strings etc. I just didn't want to post them)
Everything works except this last line:
AWSServiceManager.defaultServiceManager().setDefaultServiceConfiguration(defaultServiceConfiguration)
It errors saying:
"Value of type 'AWSServiceManager' has no member 'setDefaultServiceConfiguration'"
Why is everything working except for this line? What's wrong?
AWSServiceManager has no setter for defaultServiceConfiguration.
Instead you have to use
AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = defaultServiceConfiguration
This'll work.
Related
I'm just trying to configure the new GoogleSignIn IOS and keep getting the error.
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'No active configuration. Make sure GIDClientID is set in Info.plist.'
I've scoured the web and the one or two questions on here for solutions however I can't seem to get this error to clear no matter what. This is in my URL Schemes:
and this is my Info.plist
Does anyone have any examples of exactly how my info.plist should look?
Cheers.
I've just faced a similar issue when implementing Firebase Authentication w/ GoogleSignIn.
If you think that you will add new property "GIDClientID" into Info.plist of target project, DON'T DO THAT.
Below are the guidelines of Firebase for Authentication w/ Google, this code fixes the issue above but the way it shows how to use signIn method is invalid at this moment:
guard let clientID = FirebaseApp.app()?.options.clientID else { return }
// Create Google Sign In configuration object.
let config = GIDConfiguration(clientID: clientID)
// Start the sign in flow!
GIDSignIn.sharedInstance.signIn(with: config, presenting: self) { [unowned self] user, error in
// ...
}
There's a solution is to set the configuration to GIDSignIn.sharedInstance before calling signIn method, as below:
guard let clientID = FirebaseApp.app()?.options.clientID else { return }
// Create Google Sign In configuration object.
let config = GIDConfiguration(clientID: clientID)
GIDSignIn.sharedInstance.configuration = config
let scenes = UIApplication.shared.connectedScenes
let windowScenes = scenes.first as? UIWindowScene
let window = windowScenes?.windows.first
guard let rootViewController = window?.rootViewController else { return }
GIDSignIn.sharedInstance.signIn(withPresenting: rootViewController) { signInResult, error in
// ...
}
I am an Android developer who start learning iOS development. I am still learning so please expect some basic questions here.
Here is what I try to achieve: I have an existing SQLite database (kanadb.db) and I would like to use it in my iOS application. I would like to use an ORM to work with this database (the access will be read only) so I dropped the .db file in the project folder and did this in AppDelegate.swift:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
SharkORM.setDelegate(self)
SharkORM.openDatabaseNamed("kanadb")
// -- Test --
// Try to load some data from the database
let results: SRKResultSet = Info.query().fetch()
print(results)
// ----------
return true
}
But it is not working. I noticed that it creates a new kanadb.db in a folder somewhere in the file system. Something similar is done in Android, at startup we need to see if the DB already exist in the app folder and if not, copy the database from the bundle to the app folder. It looks like I have to do something similar here but I don't know how, as I am still new to iOS.
Can anyone give me some hints / code snippet to would point me to the correct direction?
Thank you!
I just found the solution, so I will post it here, it can be useful for someone.
So, as I expected, we have to copy the bundled database to the document folder of the application. However, the database file must be available in the target, so we have to select it in the files list (in XCode) and check Target Membership.
Then, copy it to the Document folder before using it:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let DB_NAME = "kanadb"
let DB_EXTENSION = "db"
do{
let databasePath = Bundle.main.url(forResource: DB_NAME, withExtension: DB_EXTENSION)
let documentsDirectory = try FileManager.default.url(for: FileManager.SearchPathDirectory.documentDirectory, in:FileManager.SearchPathDomainMask.userDomainMask, appropriateFor:nil, create:false)
let destination = documentsDirectory.appendingPathComponent(DB_NAME + "." + DB_EXTENSION)
_ = try FileManager.default.copyItem(at: databasePath!, to:destination)
} catch {
// TODO: Catch the errors more gracefuly
print("Couldn't copy the database to the document folder")
}
// Override point for customization after application launch.
SharkORM.setDelegate(self)
SharkORM.openDatabaseNamed(DB_NAME)
// -- Test --
// Try to load some data from the database
let results: SRKResultSet = Info.query().fetch()
print(results)
// ----------
return true
}
And that's it! Now it may be a good idea to check if the database already exist in the Document folder of the app to avoid doing that everytime we launch the app.
I've just installed GoogleAnalytics from CocoaPods and tried to use it, suddenly it crashes with an error:
fatal error: unexpectedly found nil while unwrapping an Optional value
The crash occurs in this part:
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
let tracker = GAI.sharedInstance().defaultTracker
tracker.set(kGAIScreenName, value: "Main")
let builder = GAIDictionaryBuilder.createScreenView()
tracker.send(builder.build() as [NSObject : AnyObject])
}
And when reaching this line:
tracker.set(kGAIScreenName, value: "Main")
Maybe it has something to do with the framework is bridged from Objective-C?
Update
So I fixed the crash by wrapping it with an if statment and still nothing sent to Google Analytics:
let name = "Main"
if let gai = GAI.sharedInstance() {
if let tracker: GAITracker = gai.trackerWithTrackingId("TRACKING_ID") {
tracker.set(kGAIScreenName, value: name)
let builder = GAIDictionaryBuilder.createScreenView()
tracker.send(builder.build() as [NSObject : AnyObject])
print("tracker initialized")
}
}
The docs for the GAI class have this to say about defaultTracker
>
For convenience, this class exposes a default tracker instance.
This is initialized to nil and will be set to the first tracker that is instantiated in trackerWithTrackingId:. It may be overridden as desired.
So I'm guessing you need to call trackerWithTrackingId: somewhere, or if you are already doing it, make sure it happens before this method is called.
So I figured out the problem, I used Google Analytics with CocoaPods as explained in the Google Analytics iOS tutorial and added this line to the Bridging Header file:
#import <Google/Analytics.h>
but I guess that's not enough, after adding these lines:
#import <GoogleAnalytics/GAI.h>
#import <GoogleAnalytics/GAIDictionaryBuilder.h>
#import <GoogleAnalytics/GAILogger.h>
#import <GoogleAnalytics/GAITrackedViewController.h>
#import <GoogleAnalytics/GAITracker.h>
It worked perfect. (Thanks Rich Tolley for the help)
For me I had to add those lines in the AppDelegate:
var configureError:NSError?
GGLContext.sharedInstance().configureWithError(&configureError)
assert(configureError == nil, "Error configuring Google services: \(configureError)")
I am trying to integrate Parse into a Swift app. I downloaded the SDK, set the app id and added the dependencies, but when I try to import Parse, it says 'No such module - Parse'.
Check that the Parse framework has been copied to your project folder to wherever you keep your 3rd party dependencies (e.g. Vendor).
Then, add the path to the Parse framework to the Framework Search Paths (FRAMEWORK_SEARCH_PATHS) for your build target.
It should look something like this:
$(inherited)
$(PROJECT_DIR)/Vendor/Parse
I'd clean up the DerivedData folder and rebuild.
I think this link should be solve your Problem:
Set up new Parseproject
or here ist explained it for a existing project please check this
Edit after i saw the Code. At first please do not post api keys here this are your private api keys.
second i think the code should look like:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
Parse.enableLocalDatastore()
// Initialize Parse.
Parse.setApplicationId("appID",
clientKey: "Key")
// [Optional] Track statistics around application opens.
PFAnalytics.trackAppOpenedWithLaunchOptions(launchOptions)
//end parse
// Override point for customization after application launch.
let splitViewController = self.window!.rootViewController as! UISplitViewController
let navigationController = splitViewController.viewControllers[splitViewController.viewControllers.count-1] as! UINavigationController
navigationController.topViewController.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem()
splitViewController.delegate = self
let masterNavigationController = splitViewController.viewControllers[0] as! UINavigationController
let controller = masterNavigationController.topViewController as! MasterViewController
controller.managedObjectContext = self.managedObjectContext
return true
}
you have to put in your Key i corrected the method for you
My problem appears to have been in the naming of the application: I included a number.
Once I corrected this, the error disappeared. Perhaps the name prevents the import of certain frameworks.
I was following this tutorial to add google sign in in my iOS app using swift. I followed all the steps as mentioned but when I try to build app then it is giving me an issue in my appdelegate.swift file.
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
var configureError: NSError?
GGLContext.sharedInstance().configureWithError(&configureError)
assert(configureError == nil, "Error configuring Google services: \(configureError)")
GIDSignIn.sharedInstance().clientID = "client id"
return true
}
so below line of code
GGLContext.sharedInstance().configureWithError(&configureError)
Error text is "Use of unresolved identifier GGLContext". What could be the issue here ?
in Bridging-Header.h
import <GoogleSignIn/GoogleSignIn.h>
import <Google/Core.h>
in AppDelegate.swift
import Google
Preliminary:
I have been annoyed for a few days now that when I integrated the Cocoapod Google/SignIn that I was getting Thread warnings. After digging into everything, I may have found a solution. This probably would only be something worth looking at if the only aspect of google you want in your project in sign in. If you have Firebase or any other part of google integrated, you probably will never hit an issue that leads you to this thread though.
OK, after delving into this problem for a bit, I found my solution to be:
In Bridging Header import only #import <GoogleSignIn/GoogleSignIn.h>
In AppDelegate import only import GoogleSignIn
In Podfile import only pod 'GoogleSignIn'
In AppDelegate didFinishLaunchingWithOptions do domething like this:
if let path = Bundle.main.path(forResource: "GoogleService-Info", ofType: "plist"),
let googleInfo = NSDictionary(contentsOfFile: path),
let clientId = googleInfo["CLIENT_ID"] as? String {
GIDSignIn.sharedInstance().clientID = clientId
}
GIDSignIn.sharedInstance().delegate = self
and remove:
var configureError: NSError?
GGLContext.sharedInstance().configureWithError(&configureError)
assert(configureError == nil, "Error configuring Google services: \(configureError!)")
With this setup, everything seems to be working great. I got the idea by looking at the link below. Let me know if this works for you.
https://github.com/googlesamples/google-services/blob/master/ios/signin/SignInExampleSwift/AppDelegate.swift
I found the solution, You can use the Bridge-Header.h file and import like that
#ifndef Bridge_header_h
#define Bridge_header_h
#import "Google/Core.h"
#import "GoogleSignIn.h"
#endif /* Bridge_header_h */
it's work perfectly at my end.
in swift, the below worked for me.
import GoogleSignIn