Firebase Analytics.logEvent() doesn't work, but native event are ok - ios

First of all, here are my steps:
Pod Firebase/Analytics 7.5.0 : OK
FirebaseApp.configure() in app.delegate : OK
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
guard let window = self.window else { return false }
FirebaseConfiguration.shared.setLoggerLevel(.max)
FirebaseApp.configure()
Analytics.setAnalyticsCollectionEnabled(true)
Google plist : OK ( tested with anther blank application it does work )
No env var stored
Debug mode : OK
I do have firebase's native event as Screen view, session_start etc :
[Firebase/Analytics][I-ACS023072] Event logged. Event name, event params: screen_view (_vs)
but as soon as I send myself an event, nothing in DebugViews ( Xcode + Firebase console )
Analytics.logEvent("event", parameters: nil)
What did I miss, configuration, conflicts between some pods ?
Regards

Related

MXMetricKit: finishExtendedLaunchMeasurement not work

Xcode throw an error when i call the api finishExtendedLaunchMeasurement :
[General] Couldn't find persisted ALM/FrontBoard launch signpost id when finishing an ext launch task.
Error Domain=MXErrorDomain Code=5 "Internal failures happened inside of MetricKit." UserInfo={NSLocalizedDescription=Internal failures happened inside of MetricKit.}
The following code:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// create window
MXMetricManager.shared.add(self)
do {
let task_id = MXLaunchTaskID("1234.zmmm")
try MXMetricManager.extendLaunchMeasurement(forTaskID: task_id)
print("some task perform")
try MXMetricManager.finishExtendedLaunchMeasurement(forTaskID: task_id)
} catch {
print(error)
}
return true
}
how i can fix this problem?
you should not call finishExtendedLaunchMeasurement here
because the app is not launch completely there.
just do it like this, or any other time you want, such as the first screen showed
dispatch_async(dispatch_get_main_queue(), ^{
if (#available(iOS 16.0, *)) {
[[MetricsManager shared] finishLaunchMeasurement];
}
});

iOS - Initialise WebEngage SDK Conditionally with different Accounts Ids

I am in need of Initialising WebEngage SDK based on some conditions.
if condition {
//initialise with `X` Account ID
} else {
//initialise with `Y` Account ID
}
But as per WebEnage-Documentation there is no method for initialising SDK with accountId.
we just call below code in our AppDelegate's didFinishLaunchingWithOptions method.
WebEngage.sharedInstance().application(application,
didFinishLaunchingWithOptions: launchOptions)
and it initialise the SDK by reading account id from info.plist file.
I tried updating Info.plist at run time but that didn't work.
I am looking for the right approach to do it.
In WebEngage v6.0.0 a new initialising method is introduced that can have licenseCode as parameter.
func application(_ application: UIApplication?, didFinishLaunchingWithOptions launchOptions: [AnyHashable : Any]?, notificationDelegate: WEGInAppNotificationProtocol?, autoRegister apnRegister: Bool, setLicenseCode licenseCode: String?) -> Bool
I initialises SDK with help of above method in AppDelegate's didFinishLaunchingWithOptions method.
if staging {
WebEngage.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions, setLicenseCode: "xyz")
} else {
WebEngage.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions, setLicenseCode: "abc")
}

How do I prevent Alert when App is on Foreground with Incoming OneSignal Push Notification?

When my app is in the foreground, there is a alert that appears. How do I prevent this from appearing when receiving push notifications?
In your didFinishLaunchingWithOptions method of AppDelegate you have to add kOSSettingsKeyInAppAlerts = NO
[OneSignal initWithLaunchOptions:launchOptions appId:ONESIGNAL_APPID handleNotificationReceived:nil handleNotificationAction:nil
settings:#{kOSSettingsKeyInAppAlerts:#NO}];
For Swift 3.0
// Initialize OngeSignal with Settings for Push Notifications
OneSignal.initWithLaunchOptions(launchOptions, appId: Constants.OneSignalAppID, handleNotificationReceived: nil, handleNotificationAction: {
(result) in
// Do Something with Notification Result
}, settings: [kOSSettingsKeyInFocusDisplayOption : OSNotificationDisplayType.none.rawValue])
By default OneSignal shows notifications as alert dialogs when the app is infocus. To change this pass kOSSettingsKeyInFocusDisplayOption with the value OSNotificationDisplayTypeNotification or OSNotificationDisplayTypeNone to settings on initWithLaunchOptions.
I achieved it this way. Add the following code in your AppDelegate didFinishLaunchingWithOptions
OneSignal.inFocusDisplayType = OSNotificationDisplayType.none
on last line in
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
OneSignal.inFocusDisplayType = OSNotificationDisplayType.none
return true }
we have these 3 options
public enum OSNotificationDisplayType : UInt {
/*Notification is silent, or app is in focus but InAppAlertNotifications are disabled*/
case none
/*Default UIAlertView display*/
case inAppAlert
/*iOS native notification display*/
case notification
}
Here's OneSignal Documentation

Force touch the app icon when app closed from task manager

while using quick actions of 3D Touch it works good but while app is terminated first time force touch the app icon it open home screen but the other times it open the right screen.
why this happen and how I can test the app while it is terminated
From the method application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) you can use the launchOptions argument to detect whether user is launching the app by pressing shortcut item key or not.
if launchOptions != nil {
if let userInfo = launchOptions![UIApplicationLaunchOptionsShortcutItemKey] {
//Handled the implementation here
}
}

What is actually the value of UIApplicationBackgroundFetchIntervalMinimum?

I'm about setting up background fetch for an iOS application.
I do:
func application(
application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?
) -> Bool {
...
application.setMinimumBackgroundFetchInterval(
UIApplicationBackgroundFetchIntervalMinimum)
...
if I inspect and print UIApplicationBackgroundFetchIntervalMinimum in the debugger it says 0 - what is the value actually ?
I tried looking through the api as well but no luck https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/#//apple_ref/occ/instm/UIApplication/setMinimumBackgroundFetchInterval:
It is not specified by Apple how long UIApplicationBackgroundFetchIntervalMinimum time is, however in practice it is around 10 minutes.

Resources