【问题标题】:Getting app data from custom uri in NDEF Record on nfc tag (Windows Phone 8)从 nfc 标签上的 NDEF 记录中的自定义 uri 获取应用数据(Windows Phone 8)
【发布时间】:2013-07-13 15:44:23
【问题描述】:

我已经定义了一个自定义 URI 方案并将其添加到 App Manifest。

 <Extensions>
        <Protocol Name="mycustomuri" NavUriFragment="encodedLaunchUri=%s" TaskID="_default" />
      </Extensions>

这会触发一个弹出窗口“接收内容 - 这将打开一个与 mycustomuri 关联的应用程序”。 到目前为止一切正常,标签和 uri 玩得很好。但是,附加到每个标签上的 URI 的是一个唯一的 id。目的是,当检测到此自定义 URI 时,我的应用程序将打开,导航到“DetectTag.xaml”并将 ID 显示为 TextBlock。

这是我的 Association Uri Mapper 类。

class AssociationUriMapper : UriMapperBase
{
    private string tempUri;
public override Uri MapUri(Uri uri)
    {
        tempUri = System.Net.HttpUtility.UrlDecode(uri.ToString());
        // URI association launch for my app detected
        if (tempUri.Contains("mycustomuri:uid"))
        {
            // Get the category (after "Category=").
            int uidIndex = tempUri.IndexOf("uid");
            string uid = tempUri.Substring(uidIndex);
            // Redirect to the MainPage.xaml with the proper category to be displayed
            return new Uri("/DetectTag.xaml" + uid, UriKind.Relative);
        }
        // Otherwise perform normal launch.
        return uri;
    }

谁能告诉我哪里出错了?当我点击标签并接受提示时,调试器会在 NavigationFailed 处中断。

谢谢。

【问题讨论】:

    标签: c# windows-phone-8 uri nfc ndef


    【解决方案1】:

    已解决

    更改了标签的内容和 Uri Mapper。

    标签现在看起来像这样......

    mycustomuri:uid?uid=00001
    

    UriMapper 相应更改:

    class AssociationUriMapper : UriMapperBase
    {
        public bool uidFound;
    
        private string tempUri;
        public override Uri MapUri(Uri uri)
        {
            tempUri = System.Net.HttpUtility.UrlDecode(uri.ToString());
            // URI association launch for my app detected
            if (tempUri.Contains("mycustomuri:uid?uid="))
            {
                // Get the category (after "Category=").
                int uidIndex = tempUri.IndexOf("uid=")+7;
                string uid = tempUri.Substring(uidIndex);
                // Redirect to the MainPage.xaml with the proper category to be displayed
                return new Uri("/DetectTag.xaml?uid=" + uid, UriKind.Relative);
            }
            // Otherwise perform normal launch.
            return uri;
        }
    }
    

    为了完整起见,这里是用户被定向到的页面。

    public partial class DetectTag : PhoneApplicationPage
    {
        int uid;
        public DetectTag()
        {
            InitializeComponent();
        }
    
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (NavigationContext.QueryString.ContainsKey("uid"))
            {
                uid = int.Parse(NavigationContext.QueryString["uid"]);
            }
            base.OnNavigatedTo(e);
    
            string stringUid = uid.ToString();
            tagID.Text = stringUid;
    
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-10
      • 1970-01-01
      • 1970-01-01
      • 2017-06-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多