Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows 10 Mobile #221

Closed
ruisilva450 opened this issue Dec 21, 2015 · 19 comments
Closed

Windows 10 Mobile #221

ruisilva450 opened this issue Dec 21, 2015 · 19 comments

Comments

@ruisilva450
Copy link

Hi,
I tried to use your plugin on a Lumia 920 and 950XL and both returned NO_NFC_OR_NFC_DISABLED everytime on nfc.addNdefListener(callback, [onSuccess], *[onFailure]* );

I have NFC enabled on both devices

Thank you

@don
Copy link
Member

don commented Dec 21, 2015

I haven't run with with Windows 10 yet, just Windows 8.1 on my Lumia 640. Maybe the API or permissions changed for Windows 10? Are you seeing any error messages in Visual Studio?

@ruisilva450
Copy link
Author

No. And I'm seeing logs that the plugin is successfully recognizing NFC tags.

@don
Copy link
Member

don commented Dec 22, 2015

It looks like this is a permission issue.

I had a Cordova app on the phone before upgrading the phone to Windows 10 and it ran fine after upgrading. It was able to read NFC tags.

I recreated the app and deployed from Visual Studio 2015 onto the Windows 10 phone and I got a permission error.

vs_nfc_permission

To recreate the app I was using for debugging.

cordova create nfc com.example.nfc NFC
cd nfc
cordova platform add windows
cordova plugin add phonegap-nfc

edit www/js/index.js and replace onDeviceReady with

onDeviceReady: function() {
    app.receivedEvent('deviceready');

    // Read NDEF formatted NFC Tags
    nfc.addNdefListener (
        function (nfcEvent) {
            var tag = nfcEvent.tag,
                ndefMessage = tag.ndefMessage;

            // dump the raw json of the message
            // note: real code will need to decode
            // the payload from each record
            alert(JSON.stringify(ndefMessage));

            // assuming the first record in the message has
            // a payload that can be converted to a string.
            alert(nfc.bytesToString(ndefMessage[0].payload).substring(3));
        },
        function () { // success callback
            alert("Waiting for NDEF tag");
        },
        function (error) { // error callback
            alert("Error adding NDEF listener " + JSON.stringify(error));
        }
    );
},

Open Visual Studio, switch the project to CordovaApp.Windows10 (Universal Windows) and deploy to the phone.

If you can figure out the correct permissions in Visual Studio, I can update the manifest to do this automatically.

@ruisilva450
Copy link
Author

I saw your code and it appears to be right. I changed plugin.xml to add this:

<config-file target="package.appxmanifest" parent="/Package/Capabilities">
    <DeviceCapability Name="proximity" />
</config-file>

Notice that since we are dealing with Universal Apps it makes sense that the target is package.appxmanifest and not package.xxx.appxmanifest.

Still this doesn't work and I'm out of ideas.

@don
Copy link
Member

don commented Dec 28, 2015

@ruisilva450 I think the trick is to get the generated Windows project to work, then copy those settings back to into cordova.xml.

@tervoju
Copy link

tervoju commented Mar 7, 2016

any news on this? trying this in Samsung/android - working, Lumia 950 - not working.

@lamuertepeluda
Copy link

lamuertepeluda commented May 14, 2016

👍 +1 on this issue. I had the same error as @don and I had to add proximity capability manually for win 10 universal app in order to avoid that runtime error. I think you should just add one more line in the plugin.xml. I'll check how I did for another plugin and let u know

@lamuertepeluda
Copy link

This is working in my plugin.xml - taken from a different plugin not this one - to support windows phone 8.1, windows 8.1 and 10.

 <platform name="windows">
    <config-file target="package.appxmanifest" parent="/Package/Capabilities" versions="8.1.0">
        <m2:DeviceCapability Name="bluetooth.rfcomm">
            <m2:Device Id="any">
                <m2:Function Type="serviceId:00001101-0000-1000-8000-00805F9B34FB"/>
            </m2:Device>
        </m2:DeviceCapability>
    </config-file>
    <config-file target="package.appxmanifest" parent="/Package/Capabilities" versions=">8.1.0">
        <DeviceCapability Name="bluetooth.rfcomm">
            <Device Id="any">
                <Function Type="serviceId:00001101-0000-1000-8000-00805F9B34FB"/>
            </Device>
        </DeviceCapability>
    </config-file>
</platform>

I know the config-file items seem identical but without declaring it explicitly I was not getting win 10 manifest to be updated... I think it is because of Cordova Windows platform.
I guess you should use this pattern instead to get the manifest updated for Windows 10 as well. I will try to make a PR as soon as possible.

@rancano
Copy link

rancano commented May 18, 2016

I have the same issue, with nfc.addNdefListener. When i use nfc.addTagDiscoveredListener it detects the tag, but i don't have any information writen on it.

@mobidev111
Copy link

Which 'DeviceCapability' settings need to be added? bluetooth.rfcomm or proximity or both?

Goal: read NFC tags in windows 10 universal apps - especially on windows 10 desktop with nfc reader

@lamuertepeluda @ruisilva450 What is needed for windows 10 desktop - Any updates or further findings? What else needs to be done?

@lamuertepeluda
Copy link

lamuertepeluda commented Jun 30, 2016

Hi @mobidev111 , I'm sorry I didn't find much time to work on this plugin yet. Anyway I think you should only add proximity DeviceCapability, because the other one is needed for bluetooth rfcomm communication which are out of this plugin scope.

See this link and this other link for more info about capabilities.

Try if this work (I don't have access to a windows machine a.t.m. so I can't try it myself) by adding it to the plugin.xml file.

<platform name="windows">
    <config-file target="package.appxmanifest" parent="/Package/Capabilities" versions="8.1.0">
        <DeviceCapability Name="proximity" />
    </config-file>
    <config-file target="package.appxmanifest" parent="/Package/Capabilities" versions=">8.1.0">
        <DeviceCapability Name="proximity" />
    </config-file>
</platform>

If the section for version=8.1.0 causes problems, remove it and leave the part with version>=8.1.0 which is for Windows 10.

@mobidev111
Copy link

thx. this works for windows 10 mobile - without this I got the "Access Denied" message as described above (#221 (comment))

Will check for windows 10 desktop.

@don can you add this to the plugin? it definitely gets people past the "Access Denied" message on windows 10 mobile.

@jwillmer
Copy link

FYI: I did not encounter any Access denied issue as I compiled my project as a Windows Phone (Universal) app on a Lumia 950.

@lamuertepeluda
Copy link

@jwillmer This issue occurs at runtime, not compile time. Tried on Nokia Lumia 1520.

@jwillmer
Copy link

@lamuertepeluda also tested at runtime. Works as intended 👍

@andreujuanc
Copy link

Guys, this happened to me just today.
Quick fix was to addNdefListener after plugin is initialized.

I found this after I tried all described on this issue, and still didnt work.

The weird thing was also happened the same as @ruisilva450 , he said:

No. And I'm seeing logs that the plugin is successfully recognizing NFC tags

So I was pretty sure NFC was enabled and working as expecting. But some how i just went and tried to see if i was getting subscribed too early (even if i do it ondeviceready).

First, I setted a breakpoint on phonegap-nfc.js line 19: console.log("Initialized the NfcPlugin");
Second, breakpoint at the line where I subscribe with addNdefListener.

Got the addNdefListener breakpoint stop first.

Settted a timer to wait a bit until plugin is initialized, and worked fine.

Should we create an event, so users can subscribe after plugin is initialzied?

Happy Holidays!

@don
Copy link
Member

don commented Jan 7, 2017

#227 might fix this

@don
Copy link
Member

don commented Apr 18, 2018

Closing old issue. RIP Windows Mobile. Maybe #265 handles for Windows10?

@don don closed this as completed Apr 18, 2018
@andreujuanc
Copy link

@don Miss Windows Mobile so much. RIP. 🍺

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants