iOS推送通知PhoneGap

时间:2017-11-18 03:25:14

标签: javascript php ios apple-push-notifications phonegap

我正在开发一个需要推送通知的iOS设备的应用项目。 有没有关于如何做到这一点的好的和最新的教程? 我以为我可以创建一个php脚本,并且每15分钟通过cronjob调用一次,这会触发推送通知,这可能是可能的吗?

修改 1.创建index.js

// Add to index.js or the first page that loads with your app.
// For Intel XDK and please add this to your app.js.

document.addEventListener('deviceready', function () {
  // Enable to debug issues.
  // window.plugins.OneSignal.setLogLevel({logLevel: 4, visualLevel: 4});

  var notificationOpenedCallback = function(jsonData) {
    console.log('notificationOpenedCallback: ' + JSON.stringify(jsonData));
  };

  window.plugins.OneSignal
    .startInit("********************appid")
    .handleNotificationOpened(notificationOpenedCallback)
    .endInit();

  // Call syncHashedEmail anywhere in your app if you have the user's email.
  // This improves the effectiveness of OneSignal's "best-time" notification scheduling feature.
  // window.plugins.OneSignal.syncHashedEmail(userEmail);
}, false);
  1. 将代码添加到config.xml

    <gap:plugin name="onesignal-cordova-plugin" spec="^2.1.1" source="npm" /> <preference name="phonegap-version" value="cli-7.0.1" /> <preference name="android-build-tool" value="gradle" /> <preference name="android-minSdkVersion" value="15" /> <!-- Can omit if not targetting Windows Phone --> <preference name="windows-appx-target" value="8.1-phone" /> <preference name="WindowsToastCapable" value="true" />

  2. <script src="js/index.js"></script>添加到我的index.html

  3. 如果我打开我的应用,我会收到此错误:Uncaught TypeError: Cannot read property 'OneSignal' of undefined

0 个答案:

没有答案