當(dāng)前位置:首頁(yè) > IT技術(shù) > 移動(dòng)平臺(tái) > 正文

零代碼快速集成AGC崩潰服務(wù)-xamarin框架-iOS
2021-12-13 17:54:28

華為AGC的崩潰服務(wù)支持跨平臺(tái),按照文檔整理了個(gè)Xamarin插件集成的文檔,有需要的開發(fā)者可以參考。

環(huán)境配置和項(xiàng)目設(shè)置


  1. 安裝Xamarin環(huán)境

主要是先安裝visual studio for MAC,然后安裝Mobile development with .NET,具體可以參考??Xamarin環(huán)境搭建??。

零代碼快速集成AGC崩潰服務(wù)-xamarin框架-iOS_自定義

  1. AGC創(chuàng)建項(xiàng)目工程,并且開通華為分析服務(wù)。

這部分是基本操作,可以參見??創(chuàng)建項(xiàng)目???和??開通華為分析??

  1. 集成AGC Xamarin NuGet包

點(diǎn)擊創(chuàng)建的項(xiàng)目工程,右鍵選擇”Manage NuGet Packages”

零代碼快速集成AGC崩潰服務(wù)-xamarin框架-iOS_ide_02

選擇對(duì)應(yīng)的包后安裝:

零代碼快速集成AGC崩潰服務(wù)-xamarin框架-iOS_自定義_03

繼續(xù)添加HA包,注意需要選擇1.2.0.300版本:

零代碼快速集成AGC崩潰服務(wù)-xamarin框架-iOS_ide_04

  1. 添加Json文件到項(xiàng)目目錄下

零代碼快速集成AGC崩潰服務(wù)-xamarin框架-iOS_自定義_05

  1. 將“Build Action”設(shè)置為“BundleResource”。

零代碼快速集成AGC崩潰服務(wù)-xamarin框架-iOS_自定義_06

  1. 設(shè)置應(yīng)用包名。

零代碼快速集成AGC崩潰服務(wù)-xamarin框架-iOS_自定義_07

7.配置免費(fèi)預(yù)配證書 如果沒有申請(qǐng)付費(fèi)證書,可以使用免費(fèi)證書,具體參見: https://developer.huawei.com/consumer/cn/doc/development/AppGallery-connect-Guides/agc-get-started-xamarin#h2-1617333170516-2

集成實(shí)現(xiàn)


  1. 布局界面設(shè)計(jì)

雙擊main.storyboard拉起Xcode創(chuàng)建3個(gè)按鍵“MakeCrash”,” CatchException”,” CustomReport”。

零代碼快速集成AGC崩潰服務(wù)-xamarin框架-iOS_自定義_08

  1. 代碼調(diào)用

編輯 ViewController.cs 文件, 調(diào)用 AGCCrash.GetSharedInstance.TestIt 制造一次崩潰事件,調(diào)用 AGCCrash.GetSharedInstance.SetUserId 自定義用戶標(biāo)識(shí),調(diào)用 AGCCrash.GetSharedInstance.SetCustomKey 自定義鍵值對(duì),調(diào)用 AGCCrash.GetSharedInstance.Log 自定義日志級(jí)別,調(diào)用 AGCCrash.GetSharedInstance. RecordException 產(chǎn)生并記錄一次非嚴(yán)重異常。

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");

}
}

崩潰報(bào)告查看


集成完后點(diǎn)擊按鍵制造崩潰和非嚴(yán)重異常,并產(chǎn)生自定義報(bào)告,可以在AGC頁(yè)面查看

  1. 崩潰概覽

零代碼快速集成AGC崩潰服務(wù)-xamarin框架-iOS_創(chuàng)建項(xiàng)目_09

  1. 問(wèn)題概覽

零代碼快速集成AGC崩潰服務(wù)-xamarin框架-iOS_自定義_10

  1. 查看崩潰詳情堆棧

零代碼快速集成AGC崩潰服務(wù)-xamarin框架-iOS_創(chuàng)建項(xiàng)目_11

  1. 查看自定義鍵值對(duì)

零代碼快速集成AGC崩潰服務(wù)-xamarin框架-iOS_創(chuàng)建項(xiàng)目_12

  1. 查看自定義日志級(jí)別

零代碼快速集成AGC崩潰服務(wù)-xamarin框架-iOS_自定義_13

  1. 查看自定義用戶標(biāo)識(shí)

零代碼快速集成AGC崩潰服務(wù)-xamarin框架-iOS_ide_14

欲了解更多詳情,請(qǐng)參見:

1、華為AGC 崩潰服務(wù)文檔:https://developer.huawei.com/consumer/cn/doc/development/AppGallery-connect-Guides/agc-crash-introduction

2、華為AGC-崩潰服務(wù)codelab:https://developer.huawei.com/consumer/cn/codelabsPortal/carddetails/CrashService-iOS

本文摘自 :https://blog.51cto.com/u

開通會(huì)員,享受整站包年服務(wù)立即開通 >