iOS Application with Firebase doesn't start with a slow internet connection - swift

Since I upgraded to the new Firebase, my application doesn't start with a slow internet connection. It does when it is has a good connection and also when it hasn't got any connection at all. I think that I've set up everything properly since it wouldn't work at all if I made a mistake with the setup.
Here's my AppDelegate code:
import UIKit
import Firebase
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptionslaunchOptions: [NSObject: AnyObject]?) -> Bool {
UITabBar.appearance().tintColor = UIColor.redColor()
FIRApp.configure()
FIRDatabase.database().persistenceEnabled = true
return true
}
}

iOS includes a mechanism called watchdog, which will terminate any application that fails to launch in a certain time window. Any blocking task you do in application(_:didFinishLaunchingWithOptions:) has the potential to cause your app to be terminated if it takes too long. You should consider performing such tasks asynchronously.
You can put breakpoints or print statements in your code to determine which line is taking too long.

Related

Firebase errors, adding using SPM

I have installed Firebase SDK using SPM and i got this, what should i do?
IMAGE!
import UIKit
import Firebase
#main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
FirebaseApp.configure()
return true
}
The Firebase team is actively working with the gRPC team on this issue and expect to resolve it in the next month or two. It's being tracked at https://github.com/firebase/firebase-ios-sdk/issues/9790.
In the meantime, the gRPC warnings do not affect Firebase functionality and can safely be ignored.

How would you fix Xcode Firebase Integration With SwiftUI saying: format:#"`[FIRApp configure];` (`FirebaseApp.configure()` in Swift) could not find "

I am clueless as to what I need to fix this problem.
I have Firebase running in my workspace in Xcode and I followed the Firebase instructions which are:
import UIKit
import Firebase
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions:
[UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
return true
}
}
But the issue is when I run the project the simulation is white. And goes to FirApp.m and says the following code.
if (!options) {
[NSException raise:kFirebaseCoreErrorDomain
format:#"`[FIRApp configure];` (`FirebaseApp.configure()` in Swift) could not find "
#"a valid GoogleService-Info.plist in your project. Please download one "
#"from %#.",
kPlistURL];
I was following CodingWithChris with this tutorial --> https://youtu.be/1HN7usMROt8?t=2363
You must make sure the GoogleService-Info.plist does not have a look like this GoogleService-Info.plist(5) when you download it again or it will not work.
To deal with black screen the error was the following:
Failed to instantiate the default view controller for UIMainStoryboardFile 'MainStoryboard' - perhaps the designated entry point is not set?
In the storyboard, make sure to uncheck the "Is initial View Controller" because it might be getting confused with multiple view controllers.
In the app go to app target and press the Info tab. There is minus or add in the value of "Main storyboard file base name" you need to use the minus to make it go away. Then on the "General tab" clear do the same thing for "Main Interface".

Xcode didn't do anything signal SIGABRT

I've just installed Xcode and tried to run an empty app.It shows this bug, even though I didn't even touch it!
The code:
import UIKit
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}
The way to fix this was to add at least something in your app.It doesn't matter what!For me, I just added a variable and it worked.

Stripe Integrating Issues

I installed 'Stripe' in my project. However, when I follow the directions on Stripe's website to integrate and 'import Stripe' in my AppDelegate, it says 'no module' and doesn't work/comes as an error. Am I doing something wrong?
Stripe's Library is in Obj-C you will need to add a Bridging Header to be able to import it to a swift project
Extensive guide :- https://www.appcoda.com/ios-stripe-payment-integration/
Also : - https://stackoverflow.com/a/30635582/6297658 might be helpful
Try this:
update Podfile
use_frameworks!
target '**{YOUR_PROJECT_NAME}**' do
pod 'Stripe'
end
delete Podfile.lock and Pods. After install pod
your sample code AppDelegate.swift
import UIKit
import Stripe
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
STPPaymentConfiguration.sharedConfiguration().publishableKey = "pk_test_6pRNASCoBOKtIshFeQd4XMUh"
// do any other necessary launch configuration
return true
}
func applicationWillResignActive(application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
func applicationDidEnterBackground(application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}

How does xCode decide in which file to begin code execution?

I'm using xCode 6 to write a simple game in Swift. I have a variety of files in the project. How does xCode know where to begin when executing the code? It seems to me that it automatically starts with the file that, following various tutorials, I have called "GameViewController.swift." But how does it decide to use this file first? Does it scan the source files for a UIViewController object and start there?
For iOS, Swift looks for a class with the #UIApplicationMain attribute, and uses that as the Application's delegate.
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
...
}
Using that attribute is equivalent to calling the UIApplicationMain function and passing the class’s name as the name of the delegate class. That in turn will handle loading your default Storyboard and load its initial view controller.
If no #UIApplicationMain is found, Swift looks for a file called main.swift and for a function called main inside of that and calls it.
if you are using storyboards, you have a setting called "Main Interface" on your target. This offers a dropdown list where you can select the storyboard file. i.e. Main.storyboard. This setting will be written to the Info.plist file that will be loaded at start time.
In this file a view controller is set as the initial view controller and will be loaded first.
To give you an idea of Apple architecture here's an example of a Cocoa app which applies to iOS Objective-C as well:
Every application starts at main but the developer entry point is usually AppDelegate. This applies to Swift as well, even if main has disappeared from the application lifecycle. Bear in mind, that main existed just to launch the app or few minor tweaks.
If you're using Storyboards, you'll be able to set the starting screen of your app from there, conversely if everything is done in code AppDelegate will be responsible of it at this point:
func application(application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {