Because there are two decimal points in the iOS version (major.minor.patch), the property is a string not a number. The easiest thing to do is to create a user property in the Firebase web console called "iOSMajorVersion". Go to Analytics: User Properties to do this. Then in your code, get the major version and report to Firebase. It helps to make sure that you only do this once per user session. In Objective-C, you can do it through a block or async GDC dispatch.
You didn't mention if you're using Objective-C or Swift, but here is how you can do it.
Objective-C
@import Foundation;
@import Firebase;
@import UIKit;
+ (void)sendMajorOSVersionToFirebase
{
// This can only be executed once per app session.
UIDevice *myDevice = [UIDevice currentDevice];
NSString *iOSVersion = [myDevice systemVersion];
NSString *majorVersionNum;
// Two methods of getting the major version from the string
// Method 1: componentsSeparatedByString
NSArray *systemVersionArray = [iOSVersion componentsSeparatedByString:@"."];
majorVersionNum = [systemVersionArray firstObject];
// Method 2: range and substringToIndex
NSRange range = [iOSVersion rangeOfString:@"." options: nil];
majorVersion = [iOSVersion substringToIndex: range.location];
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[FIRAnalytics setUserPropertyString:majorVersion forName:@"iOSMajorVersion"];
});
}
Swift
import Firebase
import Foundation
import UIKit
class func sendMajorOSVersionToFirebase() {
// This can only be executed once per app session.
let myDevice = UIDevice.current
let iOSVersion = myDevice.systemVersion
var majorVersionNum: String
// Two methods of getting the major version from the string
// Method 1: componentsSeparatedByString
let systemVersionArray = iOSVersion.components(separatedBy: ".")
majorVersionNum = systemVersionArray.first ?? ""
// Method 2: range and substringToIndex
let range: NSRange = (iOSVersion as NSString).range(of: ".", options: nil)
majorVersion = (iOSVersion as? NSString)?.substring(to: range.location)
// TODO: ensure that the code below is executed only once.
{
FIRAnalytics.setUserPropertyString(majorVersion, forName: @"iOSMajorVersion")
}
}