How to Connect the App Delegate in Facebook SDK for iOS? - ios

i'm trying to setup the Facebook SDK Login for IOS following the Step 3: Connect the App Delegate
I couldn't find the AppDelegate.swift file.
Should I override the whole AppDelegate.m file with the following code?
// AppDelegate.swift
import UIKit
import FBSDKCoreKit
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
ApplicationDelegate.shared.application(
application,
didFinishLaunchingWithOptions: launchOptions
)
return true
}
func application(
_ app: UIApplication,
open url: URL,
options: [UIApplication.OpenURLOptionsKey : Any] = [:]
) -> Bool {
ApplicationDelegate.shared.application(
app,
open: url,
sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
annotation: options[UIApplication.OpenURLOptionsKey.annotation]
)
}
}

As I understand your iOS app is created and implemented using Objective C and so your not able to see AppDelegate.swift, If you want AppDelegate.swift then you have to create your iOS app using Swift.
AppDelegate.h/m files in Objective C are equivalent to AppDelegate.swift file in swift.
The Facebook SDK document you are referencing has given instruction with respect to swift iOS app.
You can refer below link for some Objective C code as well:
https://developers.facebook.com/docs/facebook-login/ios?sdk=fbsdk
There is no mention of Objective C in step 5. Connect Your App Delegate . However, I think you can skip this step and try from Step 6. Add Facebook Login to Your Code.(This step has both Swift and Objective-C code example.

Related

flutter remote push notification(fcm) not working IOS

android works well
2.from firebase site to iOS real device works well (below this push to ios is ok)
3. remote push from iOS to andriod works well
but remote push message to iOS not working
my Xcode
my info
my Appdelegate.swift
import UIKit
import Flutter
import Firebase
#UIApplicationMain
#objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
FirebaseApp.configure() //add this before the code below
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
Actually I had faced this issue , after long research realised that I haven't permit permission for notification, so used permission_handler plugin to ask permission for remote notification .
like this:
Future<Map<Permission, PermissionStatus>> requestPermission() async {
Map<Permission, PermissionStatus> statuses = await [
Permission.notification
].request();
return statuses;
}
Uninstall the application
add above code
Call this function at starting
give permission

App crashes, Xcode 11.5, Swift 5. NSInternalInconsistencyException .... Use the statusBarManager object on the window scene instead

I wanted to update my app after a while, but now it crashes.
I get the following as an error message:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'App called -statusBar or -statusBarWindow on UIApplication: this code must be changed as there's no longer a status bar or status bar window. Use the statusBarManager object on the window scene instead.'
What should I do? Do I have to change something in class AppDelegate?
class AppDelegate:
import UIKit
import Firebase
import CoreData
import FBSDKCoreKit
import FBSDKLoginKit
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
FirebaseApp.configure()
Database.database().isPersistenceEnabled = true
FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
return true
}
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
let handled = FBSDKApplicationDelegate.sharedInstance().application(app, open: url, sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as! String?, annotation: options[UIApplication.OpenURLOptionsKey.annotation])
return handled
}
}
I have updated XCode. Cocoapods has been updated. My Mac is up to date. I don't know what to do at the moment. I read that it is probably related to the new IOS 13 .. ...
Thanks for the help.
The error message is very explicit and clear:
'App called -statusBar or -statusBarWindow on UIApplication: this code must be changed as there's no longer a status bar or status bar window. Use the statusBarManager object on the window scene instead.
Find the offending call, somewhere in TagebuchViewController, and remove/replace it.

How to use Firebase Remote Config in AppDelegate.swift?

Based on advice, I would like to manage API keys using Firebase Remote Config to avoid hard-coding API keys like google_maps_flutter suggests. It has an AppDelegate.swift like:
import UIKit
import Flutter
import GoogleMaps
#UIApplicationMain
#objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GMSServices.provideAPIKey("YOUR KEY HERE")
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
How can the above be modified to fetch the API key from Firebase Remote Config and then pass it to GMSServices?
Based on this article, I came up with:
import UIKit
import Firebase
import Flutter
import GoogleMaps
//import os.log
#UIApplicationMain
#objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
FirebaseApp.configure()
RemoteConfig.remoteConfig().fetchAndActivate() { status, error in
let apiKey : String = RemoteConfig.remoteConfig()["Google_Maps_SDK_for_iOS_API_KEY"].stringValue ?? "MISSING";
// os_log("Google_Maps_SDK_for_iOS_API_KEY = '%#'", apiKey)
GMSServices.provideAPIKey(apiKey)
}
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
Is there a better way?
I was thinking of making this as a comment, but decided to make it as my answer as it was too long.
I think it's one way of getting keys from remoteConfig, but again failure can happen where fetch config was not retrieved. One way to solve it is by having a force refresh when it fails, but then again you are relying on firebase for those keys and if for some reason (experienced it before firebase was acquired by google) it went down your app then will be unuseable (so as for many apps).
For me, I still put my API keys bundled with the app just to make sure all the important functionality works.
Another option will be having your API Keys bundled and then having a WebService call to check for new keys once the current keys you have has expired/change. That way you have the capability to immediately expire your keys and change it to another one.

FacebookLoginSDK 4 Apple Mach-O Linker Error

I am trying to integrate FacebookLogin SDK 4 into my IOS app using Swift 3. I added the following 3 frameworks: Bolts, FBSDKCoreKit and FBSDKLoginKit. I changed my Info.plist according to Facebook documentation, created the Bridging header file, and added its path to my Build Settings.
Once I add the following line in my AppDelegate.swift file, I am getting:
Apple Mach-O Linker Error:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
return true
}
I tried the options provided here: Apple Mach-O Linker Error when compiling for device
None of them helped (unless I am missing something). Has anyone else had a similar problem? Please help.
Have u added this method in app delegate
func application(_ application: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any])
-> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, open: url as URL!, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String, annotation: [:])
}
also this one in willResignActive method
func applicationWillResignActive(_ application: UIApplication)
{
FBSDKAppEvents.activateApp()
}

Unresolved identifier "PFFacebookUtils" in swift in Xcode6

I am trying to have users login to facebook with parse but am receiving the compiler error "Use of unresolved identifier" for PFFacebookUtils, Parse, FBAppCall, and an invalid DidBecomeActive
This question has been posted before and the solution was to add the parsefacebookutils framework into your project and import it into the header file. However, I have already added the framework to my project and imported it into my header file by adding the following to the my header.
#import <Parse/Parse.h>
#import <ParseFacebookUtils/PFFacebookUtils.h>
#import <FacebookSDK/facebookSDK.h>
I am still getting the error. The following is the code from my appdelegate file:
import UIKit
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
PFFacebookUtils.initializeFacebook()
Parse.setApplicationId("parseAppId", clientKey:"parseClientKey")
}
return true
}
func application(application: UIApplication,
openURL url: NSURL,
sourceApplication: String,
annotation: AnyObject?) -> Bool {
return FBAppCall.handleOpenURL(url, sourceApplication:sourceApplication,
withSession:PFFacebookUtils.session())
}
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.
FBAppCall.handleDidBecomeActiveWithSession(PFFacebookUtils.session())
}
Could you please take a look at my code above? Not sure what the solution is.
Figured it out. You have to go into the Build Settings - Objective C Header and then type the path to your header in the debug name. For example ProjectName/HeaderName.h as according to where I had my file within my project. Normally you wouldn't have to do this, but it didn't populate for me when I created the header.

Resources