Search code examples
objective-cxcodefirebasefirebase-analyticsgoogle-analytics-sdk

firebase EXC_BAD_ACCESS logEventWithName


When using FIRAnalytics logEventWithName:parameters method application crash caused by EXC_BAD_ACCESS. This is how I call it:

[FIRAnalytics logEventWithName:name parameters:paramethers];

parameters:

name = "News_Detail"

paramethers = {
    Title = "Lorem ipsum dolor is amet";
    Category = "Lorem Ipsum Category";
    URL = "https://api.loremipsum.com.uk/Contents/GalleryAlbum?appRef=iOSLoremIpsumApp&URL=%2floremipsum%2fdolor%2fisamet-loremipsum-loremipsum";
}

only crashes on this object.

I'm using cocoapods to add library in my project with:

pod 'Google/Analytics' 

and current version for today is 3.9.0.


Solution

  • It's caused because parameter values can be up to 100 characters long. My object's URL parameter 132 characters long.

    Here is the method summary under FIRAnalytics.h:

    /// Logs an app event. The event can have up to 25 parameters. Events with the same name must have
    /// the same parameters. Up to 500 event names are supported. Using predefined events and/or
    /// parameters is recommended for optimal reporting.
    ///
    /// The following event names are reserved and cannot be used:
    /// <ul>
    ///     <li>app_clear_data</li>
    ///     <li>app_remove</li>
    ///     <li>app_update</li>
    ///     <li>error</li>
    ///     <li>first_open</li>
    ///     <li>in_app_purchase</li>
    ///     <li>notification_dismiss</li>
    ///     <li>notification_foreground</li>
    ///     <li>notification_open</li>
    ///     <li>notification_receive</li>
    ///     <li>os_update</li>
    ///     <li>session_start</li>
    ///     <li>user_engagement</li>
    /// </ul>
    ///
    /// @param name The name of the event. Should contain 1 to 40 alphanumeric characters or
    ///     underscores. The name must start with an alphabetic character. Some event names are
    ///     reserved. See FIREventNames.h for the list of reserved event names. The "firebase_" prefix
    ///     is reserved and should not be used. Note that event names are case-sensitive and that
    ///     logging two events whose names differ only in case will result in two distinct events.
    /// @param parameters The dictionary of event parameters. Passing nil indicates that the event has
    ///     no parameters. Parameter names can be up to 40 characters long and must start with an
    ///     alphabetic character and contain only alphanumeric characters and underscores. Only NSString
    ///     and NSNumber (signed 64-bit integer and 64-bit floating-point number) parameter types are
    ///     supported. NSString parameter values can be up to 100 characters long. The "firebase_"
    ///     prefix is reserved and should not be used for parameter names.
    

    Warning

    This (trimParameters) method below is guarantee you a possible data lost. Please use it carefully! It's trimming our parameters. But if you don't need information after 100 character "like in my case" you can use it:

    - (NSDictionary*)trimParameters:(NSDictionary*)paramethers {
        int maxCharacter = 100;
        NSMutableDictionary *result = [paramethers mutableCopy];
    
        for (NSString* key in result) {
            NSString *value  = [NSString stringWithFormat:@"%@", result[key]];
            if(![value isEqualToString:@""] && [value length] > maxCharacter) {
                result[key] = [value substringFromIndex:maxCharacter];
            }
        }
    
        return result;
    }
    

    and we can call this method like:

    [FIRAnalytics logEventWithName:name parameters:paramethers != nil ? [self trimParameters:paramethers] : paramethers];
    

    SOLUTION:

    Like @adbitx says in comment: "crash has been fixed in the latest version 4.0.0." For installing version "4.0.0" pod update will not help in my case.

    If anyone want to use version "4.0.0" for today need to use this pod:

    pod 'FirebaseAnalytics'
    

    or wait for other pod library's update.

    Hope it will help someone.