【问题标题】:Xamarin.Forms/iOS, got exception, "You_Should_Not_Call_Base_In_This_Method"?Xamarin.Forms/iOS,出现异常,“You_Should_Not_Call_Base_In_This_Method”?
【发布时间】:2017-03-08 06:45:05
【问题描述】:

我有一个 Xamarin.Forms 项目,并实现了第三方服务,Android 部分几乎完美,但 iOS 部署不断抛出异常。我完全不知道这个异常,因为在代码中我在方法调用中得到了所有的返回值。所以,我想知道什么是“基地”,我应该检查哪个地方?

这是一个例外:

这是引发异常的代码部分:

void Join_Clicked(object sender, System.EventArgs e)
{
    String channelName = this.Room_Name_Entry.Text;
    if (channelName != null)
    {
        if (myEngine.AgoraJoinChannel(channelName) == 0)
        {
            this.VoiceStatus.Text = "You are in the channel!";
            this.VoiceStatus.IsVisible = true;
            this.Room_Join_Button.IsEnabled = false;
        }
        else
        {
            this.VoiceStatus.Text = "You are not in the channel!";
            this.VoiceStatus.IsVisible = true;
        }
    }
    else
    {
        this.VoiceStatus.Text = "Please set the room's name!";
        this.VoiceStatus.IsVisible = true;
    }
}

这是特定于平台的实现:

using System;
using DT.Xamarin.Agora;
using TabbedPageTest.iOS;

[assembly: Xamarin.Forms.Dependency(typeof(AgoraVoiceImplement_iOS))]
namespace TabbedPageTest.iOS
{
    public class AgoraVoiceImplement_iOS : IAgora
    {
        AgoraRtcEngineKit myEngine;
        AgoraRtcEngineDelegate myDelegate;

        public AgoraVoiceImplement_iOS()
        {
            myDelegate = new AgoraRtcEngineDelegate();
            myEngine = AgoraRtcEngineKit.SharedEngineWithAppIdAndDelegate("6de68f576fda42ca92a791b38383fee8", myDelegate);
        }

        public int AgoraJoinChannel(string Channel_Name)
        {
            myEngine.SetChannelProfile(AgoraRtcChannelProfile.Communication);
            return myEngine.JoinChannelByKey(null, Channel_Name, "", 0, (Foundation.NSString arg1, nuint arg2, nint arg3) =>
            {
                myDelegate.DidJoinChannel(myEngine, arg1, arg2, arg3);
            });
        }

        public int AgoraLeaveChannel()
        {
            return myEngine.LeaveChannel((AgoraRtcStats obj) =>
            {
                myDelegate.DidLeaveChannelWithStats(myEngine, obj);
            });
        }
    }
}

非常感谢!

【问题讨论】:

  • 打破异常。查看调用堆栈。查看调用 base 的位置。可能在您的一位代表中。

标签: c# android ios xamarin xamarin.ios


【解决方案1】:

您的代码中某处有一个委托,它为该委托基实现接口/类,并调用基类实现。

Xamarin SDK 具有委托基类的概念(由于 C# 特性),但在带有协议的实际 IOS SDK ObjC 上却不是这样。因此 Xamarin 添加了此异常以在执行时对其进行标记,以查找将实现留空或添加自定义代码以处理委托回调的位置。

在代码中搜索或在调试器中添加 Break On Exception,一旦调用它将停止。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多