Welcome to the Firebase App Quality codelab. In this codelab, you'll learn how to use the Firebase platform to create iOS applications. You will implement a simple app, monitor its performance, and report a crash using Firebase.
This codelab is also available in Swift.
Clone the GitHub repository from the command line.
$ git clone https://github.com/firebase/appquality-codelab-ios
To build the starter app:
ios-starter/objc-starter
directory from your sample code download pod install
You should see the App Quality home screen appear after a few seconds. The UI should appear. However, at this point you can't track specific performance or get crash reports.
From Firebase console select Add Project.
Call the project AppQuality
, then click on Create Project.
com.google.firebase.codelab.AppQualityObjC
".123456
".On the second screen click Download GoogleService-Info.plist to download a configuration file that contains all the necessary Firebase metadata for your app. Copy that file to your application and add it to the AppQualityObjC target.
You can now click the "x" in the upper right corner of the popup to close it -- skipping steps 3 and 4 -- as you will perform those steps here.
Start by making sure the Firebase
module is imported.
@import Firebase;
Use the "configure" method in FIRApp inside the application:didFinishLaunchingWithOptions function to configure underlying Firebase services from your .plist file.
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[FIRApp configure];
return YES;
}
Firebase Performance Monitoring helps you collect performance data from your app, and then review and analyze that data in the Firebase console.
Confirm that pod 'Firebase/Performance' dependency exists in your Podfile file.
Recompile your app. Automatic traces and HTTP/S network requests are now monitored.
A custom trace is a report of performance data associated with some of the code in your app. To learn more about custom traces, see the Performance Monitoring overview. You can have multiple custom traces in your app, and it is possible to have more than one custom trace running at a time.
Start the trace before reading the file.
NSString *fileName = [NSString stringWithFormat:@"%@/perfsamplelog.txt",
documentsDirectory];
// Start tracing
FIRTrace *trace = [FIRPerformance startTraceWithName:@"request_trace"];
NSError *fileReadError;
dispatch_async(dispatch_get_main_queue(), ^{
_imageView.image = [UIImage imageWithData:data];
});
[trace stop];
NSString *contentToWrite = [contents stringByAppendingString:response.URL.absoluteString];
Each custom trace can have one or more counters to count performance-related events in your app, and those counters are associated with the traces that create them.
Set a counter with the log file's size.
if (contents) {
fileLength = contents.length;
}
[trace setIntValueForMetric:@"log_file_size" by:fileLength];
NSString *target = @"https://www.gstatic.com/mobilesdk/160503_mobilesdk/logo/2x/firebase_96dp.png";
Use another counter for the number of requests.
- (void)viewDidLoad {
.
.
[[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:
.
.
}] resume];
[trace incrementMetric:@"request_sent" byInt:1];
}
We can add custom attributes to your traces to filter the trace metrics based on these attributes on the console.
if (contents) {
fileLength = contents.length;
}
// Add custom attribute
NSString *fileLengthString = fileLength > (1024 * 1024)? @">1MB": @"<1MB";
[trace setValue:fileLengthString forAttribute:@"file_size"];
NSString *target = @"https://www.gstatic.com/mobilesdk/160503_mobilesdk/logo/2x/firebase_96dp.png";
Firebase Crashlytics allows your application to report when crashes occur and log the events leading up to the crash.
Confirm that pod 'Firebase/Crashlytics' dependency exists in your Podfile file.
${PODS_ROOT}/FirebaseCrashlytics/run
/path/to/pods/directory/FirebaseCrashlytics/upload-symbols
- (IBAction)didPressCrash:(id)sender {
NSLog(@"Crash button pressed!");
assert(NO);
}
Crashlytics uses dSYM (debugging symbol) files to generate human-readable crash reports. Adjust your build settings to change the project's debug information format:
You need to perform a one-time setup in the console before your results will appear.
In the Firebase console:
Crashlytics can't capture crashes if your build attaches a debugger at launch
You have used Firebase to monitor the quality of an app.