• 當前位置:首頁 > IT技術 > 移動平臺 > 正文

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

    華為AGC的崩潰服務支持跨平臺,按照文檔整理了個Xamarin插件集成的文檔,有需要的開發者可以參考。

    環境配置和項目設置


    1. 安裝Xamarin環境

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

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

    1. AGC創建項目工程,并且開通華為分析服務。

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

    1. 集成AGC Xamarin NuGet包

    點擊創建的項目工程,右鍵選擇”Manage NuGet Packages”

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

    選擇對應的包后安裝:

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

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

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

    1. 添加Json文件到項目目錄下

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

    1. 將“Build Action”設置為“BundleResource”。

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

    1. 設置應用包名。

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

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

    集成實現


    1. 布局界面設計

    雙擊main.storyboard拉起Xcode創建3個按鍵“MakeCrash”,” CatchException”,” CustomReport”。

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

    1. 代碼調用

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

    }
    }

    崩潰報告查看


    集成完后點擊按鍵制造崩潰和非嚴重異常,并產生自定義報告,可以在AGC頁面查看

    1. 崩潰概覽

    零代碼快速集成AGC崩潰服務-xamarin框架-iOS_創建項目_09

    1. 問題概覽

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

    1. 查看崩潰詳情堆棧

    零代碼快速集成AGC崩潰服務-xamarin框架-iOS_創建項目_11

    1. 查看自定義鍵值對

    零代碼快速集成AGC崩潰服務-xamarin框架-iOS_創建項目_12

    1. 查看自定義日志級別

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

    1. 查看自定義用戶標識

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

    欲了解更多詳情,請參見:

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

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

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

    開通會員,享受整站包年服務
    国产呦精品一区二区三区网站|久久www免费人咸|精品无码人妻一区二区|久99久热只有精品国产15|中文字幕亚洲无线码