拥有一个Xamarin表单项目,并尝试将NFC读入应用程序。目前在iOS本机方面一直存在问题。我已经在Apple门户方面设置了所有配置和选项,并在权限中添加了以下内容:
<dict>
<key>com.apple.developer.nfc.readersession.formats</key>
<array>
<string>NDEF</string>
</array>
</dict>
还添加到了info.plist中:
<key>NFCReaderUsageDescription</key>
<string>NFC tag to read NDEF messages into the application</string>
我对iOS的本机依赖项获得的代码如下:
[assembly: Dependency(typeof(RFIDScannerHelper))]
namespace MyProject.Mobile.Platform.iOS
{
public class RFIDScannerHelper : IRFIDScannerHelper
{
public bool hasRFID()
{
return true;
}
NFCNdefReaderSession Session;
public void ScanRFID(Action<string> act, VisualElement el)
{
NFChecker nfchecker = new NFChecker();
Session = new NFCNdefReaderSession(nfchecker, null, false);
Session?.BeginSession();
}
}
public class NFChecker : NSObject, INFCNdefReaderSessionDelegate
{
public Action<string> nfcFoundAction;
public void DidDetect(NFCNdefReaderSession session, NFCNdefMessage[] messages)
{
foreach (NFCNdefMessage msg in messages)
{
if (msg.Records.Count() > 0)
{
nfcFoundAction.Invoke(new NSString(msg.Records[0].Payload, NSStringEncoding.UTF8));
}
}
}
public void DidInvalidate(NFCNdefReaderSession session, NSError error)
{
var readerError = (NFCReaderError)(long)error.Code;
if (readerError != NFCReaderError.ReaderSessionInvalidationErrorFirstNDEFTagRead &&
readerError != NFCReaderError.ReaderSessionInvalidationErrorUserCanceled)
{
}
}
}
}
当此命令运行时,似乎一切正常,但是在会话开始时,它直接进入ReaderDelegate中的DidInvalidate方法,并且错误显示“会话意外失效”。
谁能告诉我我可能会错过什么?
答案 0 :(得分:0)
@matt,这是Visual Studio 2019错误。您应该在项目设置中选择Entitlements.plist,但是您不能执行此操作,因为始终在其中插入路径的“条目”处于禁用状态。我已经报告了问题