Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method for track Error #51

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions flutter_appcenter_bundle/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 3.3.3

- Upgrade native AppCenter SDK to 4.4.1 (Change Logs: [Android](https://github.com/microsoft/appcenter-sdk-android/releases/tag/4.4.1) / [IOS](https://github.com/microsoft/appcenter-sdk-apple/releases/tag/4.4.1))
- Support for AppCenter trackError #26

## 3.3.2

- Update Android deps
Expand Down
2 changes: 1 addition & 1 deletion flutter_appcenter_bundle/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ android {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

def appCenterSdkVersion = '4.2.0'
def appCenterSdkVersion = '4.4.1'
implementation "com.microsoft.appcenter:appcenter-analytics:$appCenterSdkVersion"
implementation "com.microsoft.appcenter:appcenter-crashes:$appCenterSdkVersion"
appCenterImplementation "com.microsoft.appcenter:appcenter-distribute:${appCenterSdkVersion}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ class FlutterAppcenterBundlePlugin : FlutterPlugin, MethodCallHandler, ActivityA
val properties = call.argument<Map<String, String>>("properties")
Analytics.trackEvent(name, properties)
}
"trackError" -> {
val message = call.argument<String>("message")
val properties = call.argument<Map<String, String>>("properties")
Crashes.trackError(Exception(message), properties, null)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wonder if Flutter stack could be passed somehow?

throwable.setStackTrace(new StackTraceElement[]{

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

      final Trace trace = Trace.parseVM(stack.toString()).terse;
      final List<Map<String, String>> elements = <Map<String, String>>[];

}
"isDistributeEnabled" -> {
result.success(Distribute.isEnabled().get())
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,25 @@ import AppCenterAnalytics
import AppCenterCrashes
import AppCenterDistribute

typealias MSAppCenter = AppCenter
typealias MSAnalytics = Analytics
typealias MSCrashes = Crashes
typealias MSDistribute = Distribute

public class SwiftFlutterAppcenterBundlePlugin: NSObject, FlutterPlugin {
static let methodChannelName = "com.github.hanabi1224.flutter_appcenter_bundle";
static let instance = SwiftFlutterAppcenterBundlePlugin();

public static func register(binaryMessenger: FlutterBinaryMessenger) -> FlutterMethodChannel {
let methodChannel = FlutterMethodChannel(name: methodChannelName, binaryMessenger: binaryMessenger)
methodChannel.setMethodCallHandler(instance.methodChannelHandler);
return methodChannel;
}

public static func register(with registrar: FlutterPluginRegistrar) {
register(binaryMessenger: registrar.messenger());
}

public func methodChannelHandler(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
debugPrint(call.method)
switch call.method {
Expand All @@ -35,59 +40,68 @@ public class SwiftFlutterAppcenterBundlePlugin: NSObject, FlutterPlugin {
MSDistribute.updateTrack = .private
}

MSAppCenter.start(secret, withServices:[
MSAppCenter.start(withAppSecret: secret, services:[
MSAnalytics.self,
MSCrashes.self,
MSDistribute.self,
])
case "trackEvent":
trackEvent(call: call, result: result)
return
case "trackError":
let args: [String: Any]? = (call.arguments as? [String: Any])
Crashes.trackError(
NSError(domain: Bundle.main.bundleIdentifier ?? "",
code: -1,
userInfo: [NSLocalizedDescriptionKey: args?["message"] ?? ""]),
properties: args?["properties"] as? [String: String],
attachments: nil
)
return
case "isDistributeEnabled":
result(MSDistribute.isEnabled())
result(MSDistribute.enabled)
return
case "getInstallId":
result(MSAppCenter.installId().uuidString)
return
result(MSAppCenter.installId.uuidString)
case "configureDistribute":
MSDistribute.setEnabled(call.arguments as! Bool)
MSDistribute.enabled = call.arguments as! Bool
case "configureDistributeDebug":
result(nil)
return
case "disableAutomaticCheckForUpdate":
MSDistribute.disableAutomaticCheckForUpdate()
case "checkForUpdate":
MSDistribute.checkForUpdate()
case "isCrashesEnabled":
result(MSCrashes.isEnabled())
return
case "isCrashesEnabled":
result(MSCrashes.enabled)
case "configureCrashes":
MSCrashes.setEnabled(call.arguments as! Bool)
case "isAnalyticsEnabled":
result(MSAnalytics.isEnabled())
MSCrashes.enabled = call.arguments as! Bool
return
case "isAnalyticsEnabled":
result(MSAnalytics.enabled)
case "configureAnalytics":
MSAnalytics.setEnabled(call.arguments as! Bool)
MSAnalytics.enabled = call.arguments as! Bool
default:
result(FlutterMethodNotImplemented);
return
}

result(nil);
}

private func trackEvent(call: FlutterMethodCall, result: FlutterResult) {
guard let args:[String: Any] = (call.arguments as? [String: Any]) else {
result(FlutterError(code: "400", message: "Bad arguments", details: "iOS could not recognize flutter arguments in method: (trackEvent)") )
return
}

let name = args["name"] as? String
let properties = args["properties"] as? [String: String]
if(name != nil) {
MSAnalytics.trackEvent(name!, withProperties: properties)
}

result(nil)
}
}
4 changes: 2 additions & 2 deletions flutter_appcenter_bundle/ios/flutter_appcenter_bundle.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ A new flutter plugin project.
s.author = { 'Your Company' => '[email protected]' }
s.source = { :path => '.' }
s.source_files = 'Classes/**/*'
s.dependency 'AppCenter', '~> 3.3.4'
s.dependency 'AppCenter/Distribute', '~> 3.3.4'
s.dependency 'AppCenter', '~> 4.4.1'
s.dependency 'AppCenter/Distribute', '~> 4.4.1'
s.dependency 'Flutter'
s.platform = :ios, '8.0'
s.static_framework = true
Expand Down
10 changes: 10 additions & 0 deletions flutter_appcenter_bundle/lib/flutter_appcenter_bundle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ class AppCenter {
});
}

/// Track error
static Future trackErrorAsync(String message,
[Map<String, String>? properties]) async {
await _methodChannel.invokeMethod('trackError', <String, dynamic>{
'message': message,
'properties': properties,
// Support `ErrorAttachmentLog`?
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we think support ErrorAttachmentLog is necessary?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder if it might be relevant to support passing stack trace from Dart?

runZonedGuarded<Future<void>>(() async {
  runApp(App());
}, (error, stackTrace) => AppCenter.trackErrorAsync(error, stackTrace));

});
}

/// Check whether analytics is enalbed
static Future<bool?> isAnalyticsEnabledAsync() async {
return await _methodChannel.invokeMethod('isAnalyticsEnabled');
Expand Down
2 changes: 1 addition & 1 deletion flutter_appcenter_bundle/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_appcenter_bundle
description: This plugin currently bundles AppCenter Analytics, Crashes and Distribute. To learn more about AppCenter, go to https://aka.ms/appcenterdocs
version: 3.3.2
version: 3.3.3
homepage: https://github.com/hanabi1224/flutter_appcenter_bundle
publish_to: https://pub.dev/

Expand Down