Hey I am trying to initialise a realm object in my app outside the app delegate.
Now, Since a lot of file in my app are accessing the realm file, i decide to declare it globally.
Now, by doing that I got an app rejection, reasoning crash due to this object. My code is as follows
AppDelegate.swift
import UIKit
import RealmSwift
var uiRealm = try! Realm()
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, MessagingDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
return true
}
In the above code the object is initialised as the app starts and any other methods loads.
Is it possible that I just declare an object or type Realm and the initialise it under didFinishLaunching as follows:
import UIKit
import RealmSwift
var uiRealm : Realm!
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, MessagingDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// I initialise it here
uiRealm = try! Realm()
return true
}
Will it make a difference if its declare in such form. I am a little timid about this.
Any help is highly appreciated.
P.S: I already tried declaring the realm variable in app delegate and the calling it in other classes by UIapplication.shared.delegatemethod, and it always crashes.
Related
With UIKit and UIApplicationDelegate logic, I used to initialize all the frameworks and stuff in the good old applicationDidFinishLaunching... like this:
#UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
Parse.initialize(with: ParseClientConfiguration() {
$0.applicationId = PARSE_APP_ID
// ...
})
FirebaseApp.configure()
// etc...
}
}
I'm now learning how to use SwiftUI, but since there is no more UIApplicationDelegate, and I've never really used UISceneDelegate before, I don't really know where I should do this.
Thank you for your help.
my app has a struct that implements App, and this struct uses a custom AppDelegate. This is my entire AppDelegate:
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
application.registerForRemoteNotifications()
return true
}
}
I would like to get rid of this AppDelegate and call application.registerForRemoteNotifications() in the App implementation. Is this currently possible with SwiftUI 2.0 or later?
I have a standard AppDelegate file in my Xcode project, I'm experimenting with Firebase and as soon as I imported it & added
FirebaseApp.configure()
I was flagged with purple warnings: Click me
The whole AppDelegate looks as follows
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
}
These warnings never appeared whilst using Xcode 8, as a novice I am unsure on how to fix this, I have read that adding a DispatchQueue.main.async can fix it but I'm not sure where to add this.
Thanks!
App is crashing while configure firebase,Unable to resolve
Error:libc++abi.dylib: terminating with uncaught exception of type NSException
Code:
import UIKit
import Firebase
import FirebaseDatabase
import CoreData
import IQKeyboardManagerSwift
let mainUrl = "https://gopolly.com/well.php/"
#UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate
{
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool
{
FirebaseApp.configure()
IQKeyboardManager.sharedManager().enable=true
return true
}
Check if the application works without Firebase. Delete or comment out the lines of connection to the Firebase.
If the application is working without errors, then go back to the initial code and check the GoogleService-Info.plist. The BUNDLE_ID must be the same as the Bundle Identifier of the application.
I am trying to implement a banner ad in my app and have run into a roadblock.
This is my code:
import UIKit
import Firebase
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
FIRApp.configure()
GADMobileAds.configure(withApplicationID: "APPID HERE")
return true
}
This is my error:
Use of unresolved identifier GADMobileAds
I have been watching a few videos now and can't seem to find out where I have gone wrong, any help would be appreciated.