华为AGC的崩溃服务支持跨平台,按照文档整理了个Xamarin插件集成的文档,有需要的开发者可以参考。
环境配置和项目设置
- 安装Xamarin环境
主要是先安装visual studio for MAC,然后安装Mobile development with .NET,具体可以参考Xamarin环境搭建。

- AGC创建项目工程,并且开通华为分析服务。
这部分是基本操作,可以参见创建项目和开通华为分析
- 集成AGC Xamarin NuGet包
点击创建的项目工程,右键选择”Manage NuGet Packages”

选择对应的包后安装:

继续添加HA包,注意需要选择1.2.0.300版本:

- 添加Json文件到项目目录下

- 将“Build Action”设置为“BundleResource”。

- 设置应用包名。

7.配置免费预配证书 如果没有申请付费证书,可以使用免费证书,具体参见: https://developer.huawei.com/consumer/cn/doc/development/AppGallery-connect-Guides/agc-get-started-xamarin#h2-1617333170516-2
集成实现
- 布局界面设计
双击main.storyboard拉起Xcode创建3个按键“MakeCrash”,” CatchException”,” CustomReport”。

- 代码调用
编辑 ViewController.cs 文件, 调用 AGCCrash.GetSharedInstance.TestIt 制造一次崩溃事件,调用 AGCCrash.GetSharedInstance.SetUserId 自定义用户标识,调用 AGCCrash.GetSharedInstance.SetCustomKey 自定义键值对,调用 AGCCrash.GetSharedInstance.Log 自定义日志级别,调用 AGCCrash.GetSharedInstance. RecordException 产生并记录一次非严重异常。
using System;
using UIKit;
using Huawei.Agconnect.Crash;
using Foundation;
namespace crashios0512
{
public partial class ViewController : UIViewController
{
public ViewController(IntPtr handle) : base(handle)
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
// Perform any additional setup after loading the view, typically from a nib.
}
public override void DidReceiveMemoryWarning()
{
base.DidReceiveMemoryWarning();
// Release any cached data, images, etc that aren't in use.
}
partial void MakeCrash(UIKit.UIButton sender)
{
AGCCrash.GetSharedInstance().TestIt();
}
partial void CatchException(UIKit.UIButton sender)
{
AGCCrash.GetSharedInstance().RecordError(new Foundation.NSError());
}
partial void CustomReport(UIKit.UIButton sender)
{
AGCCrash.GetSharedInstance().SetUserId("testuser");
AGCCrash.GetSharedInstance().Log("default info level");
AGCCrash.GetSharedInstance().SetCustomValue(new NSString("test"), "this is string value");
AGCCrash.GetSharedInstance().LogWithLevel(AGCCrashLogLevel.Warning, "this is warning log level");
AGCCrash.GetSharedInstance().SetCustomValue(new NSNumber(123), "this is number");
}
}
更多文章请关注《万象专栏》
转载请注明出处:https://www.wanxiangsucai.com/read/cv74800