Skip to content

Commit

Permalink
Merge pull request #21 from capacitor-community/appcenter-crashes
Browse files Browse the repository at this point in the history
Appcenter crashes
  • Loading branch information
johnborges authored Jun 16, 2021
2 parents ba3ed8a + d1cf295 commit 1d6c22c
Show file tree
Hide file tree
Showing 13 changed files with 353 additions and 151 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ Example:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "https://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<dict>
<key>AppSecret</key>
<string>{APP_SECRET_VALUE}</string>
<!-- below are optional -->
<key>LogLevel</key>
<integer>2</integer>
<key>AnalyticsEnableInJs</key>
<false/>
<integer>2</integer>
<key>AnalyticsEnableInJs</key>
<false/>
<key>AnalyticsTransmissionInterval</key>
<integer>3</integer>
<integer>3</integer>
<key>CrashesEnableInJs</key>
<false/>
<false/>
<key>CrashesAlwaysSend</key>
<false/>
</dict>
<false/>
</dict>
</plist>
```

Expand Down
8 changes: 8 additions & 0 deletions appcenter-crashes/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Change Log

## 0.3.0

### Features

* Add hasCrashedInLastSession api
* Add lastSessionCrashReport api
21 changes: 21 additions & 0 deletions appcenter-crashes/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) COPYRIGHT_YEAR COPYRIGHT_HOLDER

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
108 changes: 105 additions & 3 deletions appcenter-crashes/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,35 @@
# @capacitor-community/appcenter-crashes

App Center Crashes will automatically generate a crash log every time your app crashes. The log is first written to the device's storage and when the user starts the app again, the crash report will be sent to App Center. Collecting crashes works for both beta and live apps, i.e. those submitted to the App Store. Crash logs contain valuable information for you to help fix the crash.
<p align="center"><br><img src="https://user-images.githubusercontent.com/236501/85893648-1c92e880-b7a8-11ea-926d-95355b8175c7.png" width="128" height="128" /></p>

<h3 align="center">App Center Crashes</h3>
<p align="center"><strong><code>@capacitor-community/appcenter-crashes</code></strong></p>
<p align="center">
App Center Crashes will automatically generate a crash log every time your app crashes. The log is first written to the device's storage and when the user starts the app again, the crash report will be sent to App Center. Collecting crashes works for both beta and live apps, i.e. those submitted to the App Store. Crash logs contain valuable information for you to help fix the crash.
</p>

<p align="center">
<img src="https://img.shields.io/maintenance/yes/2021?style=flat-square" />
<a href="https://github.com/capacitor-community/appcenter-sdk-capacitor/tree/master/appcenter/actions?query=workflow%3A%22CI%22"></a>
<a href="https://www.npmjs.com/package/@capacitor-community/appcenter-crashes"><img src="https://img.shields.io/npm/l/@capacitor-community/appcenter-crashes?style=flat-square" /></a>
<br>
<a href="https://www.npmjs.com/package/@capacitor-community/appcenter-crashes"><img src="https://img.shields.io/npm/dw/@capacitor-community/appcenter-crashes?style=flat-square" /></a>
<a href="https://www.npmjs.com/package/@capacitor-community/appcenter-crashes"><img src="https://img.shields.io/npm/v/@capacitor-community/appcenter-crashes?style=flat-square" /></a>
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
<a href="#contributors-"><img src="https://img.shields.io/badge/all%20contributors-0-orange?style=flat-square" /></a>
<!-- ALL-CONTRIBUTORS-BADGE:END -->
</p>

## Maintainers

| Maintainer | GitHub | Social |
| -----------| -------| -------|
| John Borges | [johnborges](https://github.com/johnborges) | [@johnborges](https://twitter.com/johnborges) |

## Features

- Generate test crashes
- Get more information about a previous crash
- Customize how crashes are processed
- Enable or disable App Center Crashes at runtime

## Install

Expand All @@ -17,6 +46,9 @@ npx cap sync
* [`setEnabled(...)`](#setenabled)
* [`generateTestCrash()`](#generatetestcrash)
* [`hasReceivedMemoryWarningInLastSession()`](#hasreceivedmemorywarninginlastsession)
* [`hasCrashedInLastSession()`](#hascrashedinlastsession)
* [`lastSessionCrashReport()`](#lastsessioncrashreport)
* [Interfaces](#interfaces)

</docgen-index>

Expand Down Expand Up @@ -87,4 +119,74 @@ Check if app recieved memory warning in the last session.

--------------------


### hasCrashedInLastSession()

```typescript
hasCrashedInLastSession() => any
```

Check if the app has crashed in the last session.

**Returns:** <code>any</code>

**Since:** 0.3.0

--------------------


### lastSessionCrashReport()

```typescript
lastSessionCrashReport() => any
```

Provides details about the crash that occurred in the last app session.

**Returns:** <code>any</code>

**Since:** 0.3.0

--------------------


### Interfaces


#### ErrorReport

| Prop | Type |
| -------------------------- | ----------------------------------------- |
| **`id`** | <code>string</code> |
| **`threadName`** | <code>string</code> |
| **`appErrorTime`** | <code>string \| number</code> |
| **`appStartTime`** | <code>string \| number</code> |
| **`exceptionName`** | <code>string</code> |
| **`exceptionReason`** | <code>string</code> |
| **`device`** | <code><a href="#device">Device</a></code> |
| **`signal`** | <code>string</code> |
| **`appProcessIdentifier`** | <code>number</code> |


#### Device

| Prop | Type |
| -------------------- | ------------------- |
| **`sdkName`** | <code>string</code> |
| **`sdkVersion`** | <code>string</code> |
| **`model`** | <code>string</code> |
| **`oemName`** | <code>string</code> |
| **`osName`** | <code>string</code> |
| **`osVersion`** | <code>string</code> |
| **`osBuild`** | <code>string</code> |
| **`osApiLevel`** | <code>number</code> |
| **`locale`** | <code>string</code> |
| **`timeZoneOffset`** | <code>number</code> |
| **`screenSize`** | <code>string</code> |
| **`appVersion`** | <code>string</code> |
| **`carrierName`** | <code>string</code> |
| **`carrierCountry`** | <code>string</code> |
| **`appBuild`** | <code>string</code> |
| **`appNamespace`** | <code>string</code> |

</docgen-api>
8 changes: 8 additions & 0 deletions appcenter-crashes/ios/Plugin/AppCenterCrashesBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,12 @@ import AppCenterCrashes
public func hasReceivedMemoryWarningInLastSession() -> Bool {
return Crashes.hasReceivedMemoryWarningInLastSession
}

public func hasCrashedInLastSession() -> Bool {
return Crashes.hasCrashedInLastSession
}

public func lastSessionCrashReport() -> Dictionary<String, Any>? {
return CrashesUtil.convertReportToJs(report: Crashes.lastSessionCrashReport)
}
}
5 changes: 4 additions & 1 deletion appcenter-crashes/ios/Plugin/AppCenterCrashesPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
CAP_PLUGIN(CrashesPlugin, "Crashes",
CAP_PLUGIN_METHOD(setEnabled, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(isEnabled, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(generateTestCrash, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(generateTestCrash, CAPPluginReturnNone);
CAP_PLUGIN_METHOD(hasReceivedMemoryWarningInLastSession, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(hasCrashedInLastSession, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(lastSessionCrashReport, CAPPluginReturnPromise);

)
23 changes: 22 additions & 1 deletion appcenter-crashes/ios/Plugin/AppCenterCrashesPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class CrashesPlugin: CAPPlugin {
let alwaysSendCrashes = config["CrashesAlwaysSend"] as? Bool

if AppCenterCapacitorShared.isSdkConfigured() {
print("[CrashesPlugin] starting")
implementation.start()
}
}
Expand All @@ -38,6 +39,26 @@ public class CrashesPlugin: CAPPlugin {
}

@objc func hasReceivedMemoryWarningInLastSession(_ call: CAPPluginCall) {
call.resolve(["value": implementation.hasReceivedMemoryWarningInLastSession()])
DispatchQueue.main.async {
call.resolve(["value": self.implementation.hasReceivedMemoryWarningInLastSession()])
}
}

@objc func hasCrashedInLastSession(_ call: CAPPluginCall) {
DispatchQueue.main.async {
call.resolve(["value": self.implementation.hasCrashedInLastSession()])
}
}

@objc func lastSessionCrashReport(_ call: CAPPluginCall) {
DispatchQueue.main.async {
guard let report = self.implementation.lastSessionCrashReport() else {
call.reject("No crash report available")
return
}

call.resolve(["value": report])
}
}

}
Loading

0 comments on commit 1d6c22c

Please sign in to comment.