Meteor-Community-Packages / raix-push

DEPRECATED: Push notifications for cordova (ios, android) browser (Chrome, Safari, Firefox)
https://atmospherejs.com/raix/push
MIT License
513 stars 197 forks source link

meteor run ios-device - Got error code 8 for token 289c6277eb... #235

Open Luis16287 opened 8 years ago

Luis16287 commented 8 years ago

meteor run ios-device --mobile-server http://192.168.100.102:3000 --production

XCode console output: 2016-08-25 16:10:35.116 pushNotificationsTest[1656:437532] Apache Cordova native platform version 4.1.0 is starting. 2016-08-25 16:10:35.119 pushNotificationsTest[1656:437532] Multi-tasking -> Device: YES, App: YES 2016-08-25 16:10:35.132 pushNotificationsTest[1656:437532]

Started backup to iCloud! Please be careful. Your application might be rejected by Apple if you store too much data. For more information please read "iOS Data Storage Guidelines" at: https://developer.apple.com/icloud/documentation/data-storage/ To disable web storage backup to iCloud, set the BackupWebStorage preference to "local" in the Cordova config.xml file

2016-08-25 16:10:35.305 pushNotificationsTest[1656:437532] Using WKWebView 2016-08-25 16:10:35.306 pushNotificationsTest[1656:437532] [CDVTimer][handleopenurl] 0.176966ms 2016-08-25 16:10:35.310 pushNotificationsTest[1656:437532] [CDVTimer][intentandnavigationfilter] 3.618956ms 2016-08-25 16:10:35.310 pushNotificationsTest[1656:437532] [CDVTimer][gesturehandler] 0.158012ms 2016-08-25 16:10:35.389 pushNotificationsTest[1656:437532] Serving asset bundle version: d9b00d3fe0babf9a274b0f3d791ef6c2ac782ca5 [INFO] GCDWebServer started on port 12512 and reachable at http://localhost:12512/ 2016-08-25 16:10:35.392 pushNotificationsTest[1656:437532] [CDVTimer][webapplocalserver] 81.638038ms 2016-08-25 16:10:35.402 pushNotificationsTest[1656:437532] [CDVTimer][statusbar] 9.907007ms 2016-08-25 16:10:35.411 pushNotificationsTest[1656:437532] [CDVTimer][splashscreen] 8.849025ms 2016-08-25 16:10:35.412 pushNotificationsTest[1656:437532] [CDVTimer][TotalPluginStartup] 105.735958ms 2016-08-25 16:10:35.418 pushNotificationsTest[1656:437532] createNotificationChecker 2016-08-25 16:10:35.418 pushNotificationsTest[1656:437532] not coldstart 2016-08-25 16:10:35.420 pushNotificationsTest[1656:437532] active 2016-08-25 16:10:35.420 pushNotificationsTest[1656:437532] PushPlugin skip clear badge 2016-08-25 16:10:36.194 pushNotificationsTest[1656:437593] Push Plugin register called 2016-08-25 16:10:36.194 pushNotificationsTest[1656:437593] PushPlugin.register: setting badge to false 2016-08-25 16:10:36.194 pushNotificationsTest[1656:437593] PushPlugin.register: clear badge is set to 0 2016-08-25 16:10:36.194 pushNotificationsTest[1656:437593] PushPlugin.register: better button setup 2016-08-25 16:10:36.195 pushNotificationsTest[1656:437593] GCM Sender ID (null) 2016-08-25 16:10:36.195 pushNotificationsTest[1656:437593] Using APNS Notification 2016-08-25 16:10:36.236 pushNotificationsTest[1656:437532] Push Plugin register success: <289c6277 eb9b2904 cbe43a22 8b58ccbd 36bcabdd 45a22e98 a32e8f45 f437ae63>

This is my project structure:

myPushNotificationsTest
|------> client
|             |------> main.css
|             |------> main.html
|             |------> main.js
|------> lib
|              |------ notifications.js
|------> mobile-config.js
|------>  package.json
|------  private
|            |------> ios
|                          |------> apn-development
|                                         |------>   cert.pem
|                                         |------>   key.pem
|                          |------>  apn-production
|                          |               |------>  cert.pem
|                          |               |------>  key.pem
|                          |------>  entrust_2048_ca.cer
|                          |------>  entrust_l1c.cer
|------> server
              |------> main.js

mobile-config.js

// This section sets up some basic app metadata,
// the entire section is optional.
App.info({
  id: 'com.viboz.myPushNotificationsTest', // replace with your bundle ID
  name: 'pushNotificationsTest',               // replace with your own name
  author: 'Luis'
});

// Pass preferences for a particular PhoneGap/Cordova plugin
App.configurePlugin('phonegap-plugin-push', {
  SENDER_ID: '829xxxxxxxxx'
});

// Set up external locations the app needs access to.
App.accessRule("*", {external: false});

// Set PhoneGap/Cordova preferences
App.setPreference('BackgroundColor', '0xff0000ff');
App.setPreference('HideKeyboardFormAccessoryBar', true);

client --> main.html:

<head>
  <title>pushNotification_Meteor1344_raix3.0.3-rc.5</title>
</head>

<body>
  <h1>Welcome to Meteor!</h1>

  {{> hello}}
  {{> info}}
</body>

<template name="hello">
  <button> Press button </button>
  <p>You've pressed the button {{counter}} times.</p>
</template>

<template name="info">
  <h2>DEVICE INFO</h2>
  <ul>
    <li><a target="_blank">Device Registration ID: {{deviceId}}</a></li>
    <li><a target="_blank">Model: {{model}}</a></li>
    <li><a target="_blank">Platform: {{platform}}</a></li>
    <li><a target="_blank">UUID: {{uuid}}</a></li>
    <li><a target="_blank">Manufacturer: {{manufacturer}}</a></li>
    <li><a target="_blank">Version: {{version}}</a></li>
    <li><a target="_blank">Serial: {{serial}}</a></li>
    <li><a target="_blank">Cordova version: {{cordova}}</a></li>
  </ul>
</template>

client --> main.js

import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';

import './main.html';

Meteor.startup(() => {
  Push.debug = true;
});

Template.hello.onCreated(function helloOnCreated() {
  // counter starts at 0
  this.counter = new ReactiveVar(0);
});

Template.hello.helpers({
  counter() {
    return Template.instance().counter.get();
  },
});

Template.hello.events({
  'click button'(event, instance) {
    // increment the counter when button is clicked
    instance.counter.set(instance.counter.get() + 1);
  },
});

Template.info.onCreated(function helloOnCreated() {
  document.addEventListener("deviceready", onDeviceReady, false);
  function onDeviceReady() {
      Session.set("cordova",device.cordova);
      Session.set("model",device.model);
      Session.set("platform",device.platform);
      Session.set("uuid",device.uuid);
      Session.set("version",device.version);
      Session.set("manufacturer",device.manufacturer);
      Session.set("serial",device.serial);

      Push.Configure({
        android: {
          senderID: 829xxxxxxxxx,
          alert: true,
          badge: true,
          sound: true,
          vibrate: true,
          clearNotifications: true
          // icon: '',
          // iconColor: ''
        },
        ios: {
          alert: true,
          badge: true,
          sound: true
        }
      });

      Push.addListener('token', function(token) {
        console.log('Token: ' + JSON.stringify(token));
        alert('Token: ' + JSON.stringify(token));
        Session.set("deviceId",JSON.stringify(token));
      });
      console.log('Push.id(): ' + Push.id());

      function sendPush(pushObject){
        console.log('Pushing: ' + JSON.stringify(pushObject));
        Push.send({
            from: pushObject.from,
            title: pushObject.title,
            text: pushObject.text,
        query: {}
        });
      }
  }
});

Template.info.helpers({
  deviceId: function () {
      return Session.get("deviceId");
  },
  model: function() {
    return Session.get("model");
  },
  platform: function() {
    return Session.get("platform");
  },
  uuid: function() {
    return Session.get("uuid");
  },
  version: function() {
    return Session.get("version");
  },
  manufacturer: function() {
    return Session.get("manufacturer");
  },
  serial: function() {
    return Session.get("serial");
  },
  cordova: function() {
    return Session.get("cordova");
  }
});

lib --> notifications.js

NotificationHistory = new Mongo.Collection("notification_history");

server --> main.js

import { Meteor } from 'meteor/meteor';

Meteor.startup(() => {
  // code to run on server at startup
  Push.debug = true;
  Push.Configure({
    gcm: {
      apiKey: 'AIzaS...',
    },
    //--> DEV
    // apn: {
    //   sound: true,
    //   passphrase: 'Password2016',
    //   keyData: Assets.getText('ios/apn-development/key.pem'),
    //   certData: Assets.getText('ios/apn-development/cert.pem'),
    //   production: false,
    //   gateway: 'gateway.sandbox.push.apple.com'
    // },
    //<-- DEV
    //--> PROD
    apn: {
    sound: true,
    passphrase: 'Password2016',
    keyData: Assets.getText('ios/apn-production/key.pem'),
    certData: Assets.getText('ios/apn-production/cert.pem'),
    production: true,
    gateway: 'gateway.push.apple.com'
    },
    //<-- PROD
  });

  Push.allow({
    send: (userId, notification) => {
      // allow all users to send notifications
      return true;
    }
  });
});

Meteor.methods({
        serverNotification: function () {
            DevicesHistory.insert({
                deviceId: Session.get("deviceId"),
                addedAt: new Date()
            }, function (error, result) {
                if (error) {
                    console.log(error);
                }
            });
        },
});

METEOR@1.3.4.4 raix:push@3.0.3-rc.5 meteor add cordova:cordova-plugin-device@1.1.2 (need to install in that way or meteor show error) meteor add cordova:phonegap-plugin-push@1.6.4 (need to install in that way or meteor show error)

This is working for android, with meteor shell --> Push.send({from: 'push',title: 'Congratulations',text: 'My message!',query: {}}); i receive the push notification on android. For ios the device is registered but i get "Got error code 8 for token 289c6277eb..." when i try Push.send from meteor shell.

When i deploy my app to itunes connect the mail i receive say:

**_Dear developer,

We have discovered one or more issues with your recent delivery for "myPushNotificationTest". Your delivery was successful, but you may wish to correct the following issues in your next delivery:

Missing Push Notification Entitlement - Your app includes an API for Apple's Push Notification service, but the aps-environment entitlement is missing from the app's signature. To resolve this, make sure your App ID is enabled for push notification in the Provisioning Portal. Then, sign your app with a distribution provisioning profile that includes the aps-environment entitlement. This will create the correct signature, and you can resubmit your app. See "Provisioning and Development" in the Local and Push Notification Programming Guide for more information. If your app does not use the Apple Push Notification service, no action is required. You may remove the API from future submissions to stop this warning. If you use a third-party framework, you may need to contact the developer for information on removing the API.

After you’ve corrected the issues, you can use Xcode or Application Loader to upload a new binary to iTunes Connect.

Regards,

The App Store team_**

indesignlatam commented 8 years ago

Hi @Luis16287, That is most probably a problem with your provisioning profile, you have to solve it in developer.apple.com, you go to account -> click on Certificates, Identifiers & Profiles -> click on identifiers - app ids -> select your app -> click on edit -> select push notifications.

Maybe you already did this, sometimes provisioning profiles get weird and you may have to remove the ones you have in your pc and get new ones.

Luis16287 commented 8 years ago

In server --> main.js for apn config if use key,cert in the console i have (STDERR) ERROR: Push server could not find certData (STDERR) ERROR: Push server could not find keyData, changing to certData and keyData i have no errors:

I20160825-17:14:19.145(-3)? Push.Configure { gcm: { apiKey: 'AIzaS...' }, I20160825-17:14:19.145(-3)? apn: I20160825-17:14:19.146(-3)? { sound: true, I20160825-17:14:19.146(-3)? passphrase: 'Password2016', I20160825-17:14:19.146(-3)? keyData: 'Bag Attributes\n friendlyName: myPushNotificationTest Key\n localKeyID: 9E 33 DF 83 16 8A E8 C1 63 08 12 7C 6E E7 A7 9C 95 A0 80 28 \nKey Attributes: \n-----BEGIN RSA PRIVATE KEY-----\nProc-Type: 4,ENCRYPTED\nDEK-Info: DES-EDE3-CBC,AD5E80683C0E230A\n...\n-----END RSA PRIVATE KEY-----\n', I20160825-17:14:19.146(-3)? certData: '-----BEGIN CERTIFICATE-----\nMIIGZTCCBU2gAwIBAgIIGkwmQAIhJ64wDQYJKoZIhvcNAQELBQA...\n-----END CERTIFICATE-----\n', I20160825-17:14:19.147(-3)? production: true, I20160825-17:14:19.147(-3)? gateway: 'gateway.push.apple.com' } } I20160825-17:14:19.148(-3)? Push: APN configured W20160825-17:14:19.148(-3)? (STDERR) WARNING: Push APN is configured to production mode - but server is running from localhost I20160825-17:14:19.205(-3)? GCM configured

Luis16287 commented 8 years ago

I'm new with push notifications and meteor , I'm working a few days ago and I could only run on android notifications :(

Luis16287 commented 8 years ago

Thanks @indesignlatam, provisioning profiles are a bit confusing for me still , I'll try again to see if I have luck this time

mitiaptest commented 7 years ago

@Luis16287 Enable push notification in Xcode capabilities section.

derwaldgeist commented 7 years ago

It is important that an app is running in production mode only if

If you deploy it using Xcode's play button, iOS will always treat it as in "development" mode. This will result in errorcode 8, if the server is running on a localhost or push is not configured for development mode.

raix commented 6 years ago

I actually managed to use production certificates once - would not recommend it...