public override void DidDetectTags(NFCNdefReaderSession session, INFCNdefTag[] tags) { try { var nFCNdefTag = tags[0]; session.ConnectToTag(nFCNdefTag, CompletionHandler); string dominio = "http://boxweb.azurewebsites.net/"; string user = MainViewModel.GetInstance().User.UserId.ToString(); string tag_id = ""; string url = dominio + "index3.aspx?user_id=" + user + "&tag_id=" + tag_id; NFCNdefPayload payload = NFCNdefPayload.CreateWellKnownTypePayload(url); NFCNdefMessage nFCNdefMessage = new NFCNdefMessage(new NFCNdefPayload[] { payload }); nFCNdefTag.WriteNdef(nFCNdefMessage, delegate { session.InvalidateSession(); }); //Task task = App.DisplayAlertAsync(user_id_tag); //AppDelegate.user_id_tag = "?"; //PopupNavigation.Instance.PopAsync(); //session.InvalidateSession(); //session.Dispose(); } catch (Exception ex) { Console.WriteLine(ex); session.Dispose(); session.InvalidateSession(); } MainViewModel.GetInstance().Home = new HomeViewModel(); Xamarin.Forms.Application.Current.MainPage = new MasterPage(); }
public void DidDetectTags(NFCNdefReaderSession session, INFCNdefTag[] tags) { try { string user_id_tag = AppDelegate.user_id_tag; if (user_id_tag == "?") { Task task = App.DisplayAlertAsync("¡Primero escanea este Tag para escribirlo!"); session.InvalidateSession(); session.Dispose(); AppDelegate.user_id_tag = "?"; } else { if ((Convert.ToInt32(user_id_tag) == Convert.ToInt32(MainViewModel.GetInstance().User.UserId.ToString())) || (0 == Convert.ToInt32(user_id_tag))) { var nFCNdefTag = tags[0]; session.ConnectToTag(nFCNdefTag, CompletionHandler); string dominio = "http://boxweb.azurewebsites.net/"; string user = MainViewModel.GetInstance().User.UserId.ToString(); string tag_id = ""; string url = dominio + "index3.aspx?user_id=" + user + "&tag_id=" + tag_id; NFCNdefPayload payload = NFCNdefPayload.CreateWellKnownTypePayload(url); NFCNdefMessage nFCNdefMessage = new NFCNdefMessage(new NFCNdefPayload[] { payload }); nFCNdefTag.WriteNdef(nFCNdefMessage, delegate { Console.WriteLine("ok"); }); //Task task = App.DisplayAlertAsync(user_id_tag); } else { Task task2 = App.DisplayAlertAsync("¡Este Tag esta vinculado con otro usuario!"); session.Dispose(); session.InvalidateSession(); AppDelegate.user_id_tag = "?"; } AppDelegate.user_id_tag = "?"; PopupNavigation.Instance.PopAsync(); session.InvalidateSession(); _tagSession.InvalidateSession(); Thread.Sleep(4000); } } catch (Exception ex) { Console.Write(ex); modo_escritura = false; } }
private void ManageWriteTextOperation(NFCNdefReaderSession session, INFCNdefTag[] tags) { var nFCNdefTag = tags[0]; session.ConnectToTag(nFCNdefTag, (error) => OnNfcTagTextWriten(this, false)); NFCNdefPayload payload = NFCNdefPayload.CreateWellKnownTypePayload(textToWrite, NSLocale.CurrentLocale); NFCNdefMessage nFCNdefMessage = new NFCNdefMessage(new NFCNdefPayload[] { payload }); nFCNdefTag.WriteNdef(nFCNdefMessage, delegate { OnNfcTagTextWriten(this, true); }); }
/// <summary> /// Returns NDEF payload /// </summary> /// <param name="record"><see cref="NFCNdefRecord"/></param> /// <returns><see cref="NFCNdefPayload"/></returns> NFCNdefPayload GetiOSPayload(NFCNdefRecord record) { if (record == null) { return(null); } NFCNdefPayload payload = null; switch (record.TypeFormat) { case NFCNdefTypeFormat.WellKnown: var lang = record.LanguageCode; if (string.IsNullOrWhiteSpace(lang)) { lang = Configuration.DefaultLanguageCode; } var langData = Encoding.ASCII.GetBytes(lang.Substring(0, 2)); var payloadData = new byte[] { 0x02 }.Concat(langData).Concat(record.Payload).ToArray(); payload = new NFCNdefPayload(NFCTypeNameFormat.NFCWellKnown, NSData.FromString("T"), new NSData(), NSData.FromString(Encoding.UTF8.GetString(payloadData), NSStringEncoding.UTF8)); break; case NFCNdefTypeFormat.Mime: payload = new NFCNdefPayload(NFCTypeNameFormat.Media, record.MimeType, new NSData(), NSData.FromArray(record.Payload)); break; case NFCNdefTypeFormat.Uri: payload = NFCNdefPayload.CreateWellKnownTypePayload(NSUrl.FromString(Encoding.UTF8.GetString(record.Payload))); break; case NFCNdefTypeFormat.External: payload = new NFCNdefPayload(NFCTypeNameFormat.NFCExternal, record.ExternalType, new NSData(), NSData.FromString(Encoding.UTF8.GetString(record.Payload), NSStringEncoding.UTF8)); break; case NFCNdefTypeFormat.Empty: payload = GetEmptyPayload(); break; case NFCNdefTypeFormat.Unknown: case NFCNdefTypeFormat.Unchanged: case NFCNdefTypeFormat.Reserved: default: break; } return(payload); }
/// <summary> /// Returns NDEF payload /// </summary> /// <param name="record"><see cref="NFCNdefRecord"/></param> /// <returns><see cref="NFCNdefPayload"/></returns> NFCNdefPayload GetiOSPayload(NFCNdefRecord record) { if (record == null) { return(null); } NFCNdefPayload payload = null; switch (record.TypeFormat) { case NFCNdefTypeFormat.WellKnown: payload = NFCNdefPayload.CreateWellKnownTypePayload(Encoding.UTF8.GetString(record.Payload), NSLocale.CurrentLocale); break; case NFCNdefTypeFormat.Mime: payload = new NFCNdefPayload(NFCTypeNameFormat.Media, record.MimeType, new NSData(), NSData.FromArray(record.Payload)); break; case NFCNdefTypeFormat.Uri: payload = NFCNdefPayload.CreateWellKnownTypePayload(NSUrl.FromString(Encoding.UTF8.GetString(record.Payload))); break; case NFCNdefTypeFormat.External: payload = new NFCNdefPayload(NFCTypeNameFormat.NFCExternal, record.ExternalType, new NSData(), NSData.FromString(Encoding.UTF8.GetString(record.Payload), NSStringEncoding.UTF8)); break; case NFCNdefTypeFormat.Empty: payload = GetEmptyPayload(); break; case NFCNdefTypeFormat.Unknown: case NFCNdefTypeFormat.Unchanged: case NFCNdefTypeFormat.Reserved: default: break; } return(payload); }