Skip to content

Commit

Permalink
Update demo app for release 4.3.0 (#931)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnatolyPristensky authored Sep 20, 2021
1 parent 18bb8b0 commit b1adb4d
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 38 deletions.
19 changes: 2 additions & 17 deletions DemoApp/app/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Alert, YellowBox } from 'react-native';
import { createBottomTabNavigator, createAppContainer } from 'react-navigation';
import Toast from 'react-native-simple-toast';

import Crashes, { UserConfirmation, ErrorAttachmentLog } from 'appcenter-crashes';
import Crashes, { UserConfirmation } from 'appcenter-crashes';

import AppCenterScreen from './screens/AppCenterScreen';
import TransmissionScreen from './screens/TransmissionScreen';
Expand Down Expand Up @@ -54,22 +54,7 @@ Crashes.setListener({

getErrorAttachments(report) {
console.log(`Get error attachments for report with id: ${report.id}'`);
return (async () => {
const attachments = [];
const [textAttachment, binaryAttachment, binaryName, binaryType] = await Promise.all([
AttachmentsProvider.getTextAttachment(),
AttachmentsProvider.getBinaryAttachment(),
AttachmentsProvider.getBinaryName(),
AttachmentsProvider.getBinaryType(),
]);
if (textAttachment !== null) {
attachments.push(ErrorAttachmentLog.attachmentWithText(textAttachment, 'hello.txt'));
}
if (binaryAttachment !== null && binaryName !== null && binaryType !== null) {
attachments.push(ErrorAttachmentLog.attachmentWithBinary(binaryAttachment, binaryName, binaryType));
}
return attachments;
})();
return AttachmentsProvider.getErrorAttachments();
},

onBeforeSending() {
Expand Down
20 changes: 20 additions & 0 deletions DemoApp/app/AttachmentsProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import AsyncStorage from '@react-native-community/async-storage';
import RNFS from 'react-native-fs';
import { ErrorAttachmentLog } from 'appcenter-crashes';

const TEXT_ATTACHMENT_KEY = 'TEXT_ATTACHMENT_KEY';
const BINARY_FILENAME_KEY = 'BINARY_FILENAME_KEY';
Expand All @@ -28,6 +29,25 @@ export default class AttachmentsProvider {
}
}

static async getErrorAttachments() {
return (async () => {
const attachments = [];
const [textAttachment, binaryAttachment, binaryName, binaryType] = await Promise.all([
AttachmentsProvider.getTextAttachment(),
AttachmentsProvider.getBinaryAttachment(),
AttachmentsProvider.getBinaryName(),
AttachmentsProvider.getBinaryType(),
]);
if (textAttachment !== null) {
attachments.push(ErrorAttachmentLog.attachmentWithText(textAttachment, 'hello.txt'));
}
if (binaryAttachment !== null && binaryName !== null && binaryType !== null) {
attachments.push(ErrorAttachmentLog.attachmentWithBinary(binaryAttachment, binaryName, binaryType));
}
return attachments;
})();
}

static async saveTextAttachment(value) {
await this.updateItem(TEXT_ATTACHMENT_KEY, value);
}
Expand Down
28 changes: 26 additions & 2 deletions DemoApp/app/screens/CrashesScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import React, { Component } from 'react';
import { Image, View, Text, TextInput, Switch, SectionList, TouchableOpacity, NativeModules } from 'react-native';
import ImagePicker from 'react-native-image-picker';

import Crashes from 'appcenter-crashes';
import Crashes, { ExceptionModel } from 'appcenter-crashes';

import AttachmentsProvider from '../AttachmentsProvider';
import SharedStyles from '../SharedStyles';
Expand Down Expand Up @@ -72,6 +72,16 @@ export default class CrashesScreen extends Component {
foo.method1();
}

async trackError(includeProperties) {
try {
throw new Error('Custom error');
} catch (error) {
const properties = includeProperties ? { property1: '100', property2: '200' } : null;
const attachments = await AttachmentsProvider.getErrorAttachments();
Crashes.trackError(ExceptionModel.createFromError(error), properties, attachments);
}
}

async nativeCrash() {
// In Android debug or non app store environment for iOS.
await Crashes.generateTestCrash();
Expand Down Expand Up @@ -168,6 +178,20 @@ export default class CrashesScreen extends Component {
],
renderItem: actionRenderItem
},
{
title: 'Track error',
data: [
{
title: 'Track error',
action: () => this.trackError(false)
},
{
title: 'Track error with properties',
action: () => this.trackError(true)
},
],
renderItem: actionRenderItem
},
{
title: 'Miscellaneous',
data: [
Expand All @@ -184,7 +208,7 @@ export default class CrashesScreen extends Component {
}
],
renderItem: valueRenderItem
}
},
]}
/>
</View>
Expand Down
6 changes: 3 additions & 3 deletions DemoApp/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ target 'DemoApp' do
# use_frameworks!

# Pods for DemoApp
pod 'AppCenter/Crashes', '~> 4.2.0'
pod 'AppCenter/Analytics', '~> 4.2.0'
pod 'AppCenterReactNativeShared', '~> 4.2.0'
pod 'AppCenter/Crashes', '~> 4.3.0'
pod 'AppCenter/Analytics', '~> 4.3.0'
pod 'AppCenterReactNativeShared', '~> 4.3.0'

platform :ios, '9.0'

Expand Down
24 changes: 12 additions & 12 deletions DemoApp/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
PODS:
- AppCenter/Analytics (4.2.0):
- AppCenter/Analytics (4.3.0):
- AppCenter/Core
- AppCenter/Core (4.2.0)
- AppCenter/Crashes (4.2.0):
- AppCenter/Core (4.3.0)
- AppCenter/Crashes (4.3.0):
- AppCenter/Core
- AppCenterReactNativeShared (4.2.0):
- AppCenter/Core (= 4.2.0)
- AppCenterReactNativeShared (4.3.0):
- AppCenter/Core (= 4.3.0)

DEPENDENCIES:
- AppCenter/Analytics (~> 4.2.0)
- AppCenter/Crashes (~> 4.2.0)
- AppCenterReactNativeShared (~> 4.2.0)
- AppCenter/Analytics (~> 4.3.0)
- AppCenter/Crashes (~> 4.3.0)
- AppCenterReactNativeShared (~> 4.3.0)

SPEC REPOS:
https://msmobilecenter.visualstudio.com/SDK/_git/AppCenterSDK-Specs-Private:
- AppCenter
- AppCenterReactNativeShared

SPEC CHECKSUMS:
AppCenter: 5c495ec6b22d072d9bbd0586ddebedb30c1cca64
AppCenterReactNativeShared: de51fd65fc1b892dab6ee646e54146ac4e0dee1e
AppCenter: 1fde01d939ee7c09bc2ff982476d1a891719065c
AppCenterReactNativeShared: b150ce9f33c10395798b2a60aed2e114acd87557

PODFILE CHECKSUM: 1cfd50ac0e60eb368817430a68a13112743fc524
PODFILE CHECKSUM: 68158a0223388bbed08e7c1ba598db31fccc7cea

COCOAPODS: 1.10.1
COCOAPODS: 1.11.0
1 change: 0 additions & 1 deletion DemoApp/jest/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ Object.defineProperty(ReactNative, 'Switch', {
}
});


jest.mock('@react-native-community/async-storage', () => mockAsyncStorage);

// Mock the native image picker library
Expand Down
6 changes: 3 additions & 3 deletions DemoApp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
},
"dependencies": {
"@react-native-community/async-storage": "1.6.2",
"appcenter": "^4.2.0",
"appcenter-analytics": "^4.2.0",
"appcenter-crashes": "^4.2.0",
"appcenter": "^4.3.0",
"appcenter-analytics": "^4.3.0",
"appcenter-crashes": "^4.3.0",
"metro": "0.54.1",
"react": "16.8.3",
"react-native": "0.59.9",
Expand Down

0 comments on commit b1adb4d

Please sign in to comment.