Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

iOS 9.2: Reference Error: Can't find variable: PushNotification. #779

Closed
shastox opened this issue Apr 5, 2016 · 22 comments
Closed

iOS 9.2: Reference Error: Can't find variable: PushNotification. #779

shastox opened this issue Apr 5, 2016 · 22 comments

Comments

@shastox
Copy link

shastox commented Apr 5, 2016

I've created a new blank project PhoneGap.

Add to config.xml:

<plugin name="phonegap-plugin-push" source="npm">
<param name="SENDER_ID" value="{MY_ID}" />
</plugin>

Added code from the example: https://github.com/phonegap/phonegap-plugin-push/tree/master/example/www

Global "Object Push Notification" is not created: "Reference Error: Can't find variable: PushNotification."

Apple Certifications are correct. Development.

I use PhoneGap Build.

@gogodigimo
Copy link

I'm getting this same issue for iOS on PhoneGap Build for cli-5.1.1, cli-5.20 and cli-5.4.1. Works great on Android.

@shastox
Copy link
Author

shastox commented Apr 5, 2016

I found solution! Many people asked, look: https://github.com/phonegap/phonegap-plugin-push/issues?page=1&q=is%3Aissue+PushNotification&utf8=%E2%9C%93

<plugin name="phonegap-plugin-push" spec="1.5.3" source="npm">
    <param name="SENDER_ID" value="{ID}" />
</plugin>

Insert spec="1.5.3"

Version 1.6 is BAD for current build.phonegap!

@gogodigimo
Copy link

Fantastic, @shastox! I've been hunting this down for a while. Thanks for sharing.

@macdonst
Copy link
Member

macdonst commented Apr 5, 2016

@shastox that just means you are using an earlier version of the plugin.

@shastox
Copy link
Author

shastox commented Apr 6, 2016

@macdonst
Оf course, I know that.

@webbpage
Copy link

Exactly what I was looking for, thanks! I really wish plugins were more friendly with PGB, this happens all too often...

@ewhill
Copy link

ewhill commented Jun 28, 2016

I literally spent a whole day trying to figure out why my pgb project wasn't getting notifications. THANK YOU for the "spec='1.5.3'" tip @shastox !!

@webbpage
Copy link

@ewhill did you by chance try 1.7.2? There's been a few releases since this issue was opened.

@Dmatafonov
Copy link

thanks a lot!

@oleksiy-nesterov
Copy link

1.7.4 still has this issue

@lucorn
Copy link

lucorn commented Jul 29, 2016

you need to add this to the root config.xml:

<engine name="ios" spec="~4.1.0"/>

@KaustubhMishra
Copy link

Hey @shastox I have add this line in my config.xml
plugin name="phonegap-plugin-push" spec="1.5.3" source="npm"
param name="SENDER_ID" value="904905204931"
plugin

but still getting the error ReferenceError: Can't find variable: PushNotification can you help me please I am building AEM IOS App do you have any idea how to get resolve this issue ?

@macdonst
Copy link
Member

@KaustubhAtMobiuso do you get an error when you add the plugin because you are using an older version of cordova-ios?

@KaustubhMishra
Copy link

@shastox no i didn't get any error while adding the plugin but when I try to build the project, I got this error 'AppDelegate.h' file not found
#import "AppDelegate.h"
after that I use this command cordova platform update ios which updated the cordova-ios version to 4.3.0 and my build get success, but when I deploy the app on IOS device i got the error ReferenceError: Can't find variable: PushNotification and I have cordova version 6.4.0.

@shastox
Copy link
Author

shastox commented Nov 29, 2016

@KaustubhAtMobiuso
Do you use "Device ready" event?

@KaustubhMishra
Copy link

Yes @shastox I use device ready event and device ready event also got fire but still same issue is there.

@shastox
Copy link
Author

shastox commented Dec 2, 2016

@KaustubhAtMobiuso Show a piece of code with device ready and PushNotification.

@KaustubhMishra
Copy link

Hey @shastox this is my code for device ready and Push Notification check it.
onDeviceReady: function() {
app.receivedEvent('deviceready');
},
// Update DOM on a Received Event
receivedEvent: function(id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');

    listeningElement.setAttribute('style', 'display:none;');
    receivedElement.setAttribute('style', 'display:block;');

    console.log('Received Event: ' + id);

    var push = PushNotification.init({
        "android": {
            "senderID": "904905204931"
        },
        "browser": {},
        "ios": {
            "sound": true,
            "vibration": true,
            "badge": true
        },
        "windows": {}
    });

    push.on('registration', function (data) {
        console.log("Push::Received Registration Id");
        console.log("Push::Received Registration Id => " + data.registrationId);

        var oldRegId = generalUtils.getPreference('REGISTRATION_ID');
        if (oldRegId !== data.registrationId) {
            // Save new registration ID
            console.log(data.registrationId);
        }
    });

    push.on('error', function(e) {
        console.log("push error = " + e.message);
    });
}

@shastox
Copy link
Author

shastox commented Dec 5, 2016

Sorry, no idea.

@KaustubhMishra
Copy link

@shastox Ok

@macdonst
Copy link
Member

the PGB team has asked for people with issues regarding phonegap build please start an issue on the support forum: https://forums.adobe.com/community/phonegap/build

please include an app id of an app that can replicate this issue.

@lock
Copy link

lock bot commented Jun 3, 2018

This thread has been automatically locked.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

9 participants