Xamarin.Forms/iOS,得到异常,“You_Should_Not_Call_Base_In_This_Method”?
问题描述:
我有一个Xamarin.Forms项目,并且已经实现了第三方服务,Android部分几乎完美,但iOS部署不断抛出异常。我完全不知道这个异常,因为在代码中,我在方法调用中获得了所有返回值。所以,我想知道什么是“基地”,我应该检查哪个地方?Xamarin.Forms/iOS,得到异常,“You_Should_Not_Call_Base_In_This_Method”?
这里是个例外:
而这里的部分代码,其中抛出异常:
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);
});
}
}
}
非常感谢!
答
您的代码中有一个委托实现该委托库的接口/类,并调用基类实现。
Xamarin SDK拥有代表基类的概念(因为C#本质),但这不是实际的IOS SDK带有协议的ObjC。因此,Xamarin添加了这个异常,以便在执行时标记它,以便找到将实现保留为空的位置或添加自定义代码以处理委托上的回调。
在代码中搜索,或者在调试器中添加Break On Exception,一旦调用它就会停止。
打破例外。查看调用堆栈。看看哪里被调用。可能在您的一位代表中。 – Cheesebaron