WebViewGold 文档 · iOS
🇨🇳 中文
获取 WebViewGold

推送通知 API(OneSignal、Firebase、Pushwoosh)

使用 OneSignal、Firebase 或 Pushwoosh 向您的 iOS 应用用户发送推送通知——详解设置、深度链接和按用户定向。

Push notifications are notifications that appear on your smartphone without opening the app. These types of messages allow fantastic interaction with customers and users of the app. Your app does not have to be open to receiving these kinds of notifications. This way, your customers do not miss any important news or messages. Push Notifications are suitable for many cases, e.g., for updates to orders, live tickers, or social media community. There must be an internet connection to allow app users to receive push messages. WebViewGold supports multiple ways of reaching your users via push notifications. If you do NOT want to use push notifications at all, open Config.swift and set askforpushpermissionatfirstrun to false in order to prevent asking the app user for notification permission.

Option 1: Use Local Push Notification JavaScript API

You can insert a piece of code (JavaScript) in your website, to define a push notification, which can be shown after your app was closed (while scheduling it during the app is open). This works without OneSignal configuration at all.

  <script>
  var title = "Your cart is waiting!"; //notification title
  var message = "You have left a cart full of dreams and deals behind. Dont leave it feeling abandoned"; //notification message
  var seconds = 120; //seconds from now on
  var url = "https://myshop.org/cart.php"; //deep-linking URL

  window.location.href = "sendlocalpushmsg://push.send?s="+ seconds +"=msg!"+ message +"&!#"+ title +"&!#"+ url +"";
  </script>
            

It could be used for different situations (countdowns, happy hours, specific reminders, ...).
To cancel all scheduled local push notifications run:
  <script>
  window.location.href = "sendlocalpushmsg://push.send.cancel";
  </script>
            




Option 2: Use Pushwoosh Remote Push Notifications

WebViewGold users are eligible for two free months of Pushwoosh!
To claim this offer, please email your WebViewGold License to [email protected] and you will get a personal reply soon.

If you want to use Pushwoosh (good choice!) for push notifications in your app, just activate the options in Config.swift by setting kPushwooshEnable to true and ensure to also update the Pushwoosh_APPID in the Info.plist file with your own Pushwoosh Application ID.

Send a new push notification to your app users with Pushwoosh
Send a new push notification to your app users with Pushwoosh
Make sure to also complete Pushwoosh setup on their website including certificate import.
Congratulations, your setup is already completed. You're now ready to send push notifications:

Send a new push notification to your app users with Pushwoosh

Want to get each individual user's device ID for personalized push notifications or further processing? Simply set kPushwooshEnhanceUrl to true in Config.swift to append ?pushwoosh_id=XYZ to your WebView URL:

Send a new push notification to your app users with Pushwoosh

For example, if your WebView URL is https://www.example.org, WebViewGold will call https://www.example.org?pushwoosh_id=XYZ instead. Remember, only the initial URL request will receive this GET variable, so please save it in a session or a cookie for later use within your linked pages. Alternatively or additionally, you can retrieve & process this information on any page using JavaScript:

<script>
window.location.href = "getpushwooshid://";
alert(pushwooshplayerid);
</script>



Option 3: Use OneSignal Remote Push Notifications

If you want to use OneSignal in your app, activate these options in Config.swift (by switching the values from false to true) and make sure to also replace the placeholder oneSignalID with your own.

Activate the OneSignal features of WebViewGold for push notification support


Now Generate an iOS Push Certificate and import it:

Generate an iOS Certificate for OneSignal Push Delivery

Yay, you are done. You can send push notifications now:

Send a new push notification to your app users

If you want to use OneSignal URL Deeplinking (opens a specific URL when clicking on your notification), please add the desired URL with a custom field called url:

Enter a web address into OneSignal to enable deeplinking into your WebView app


On the OneSignal.com Backend, you can fill in this key-value-pair window after clicking on "Advanced settings". Using the OneSignal API, you can add the "url" field to the API request (https://documentation.onesignal.com/docs/onesignal-api).

Do you want to get each individual subscription ID on your server for further processing and individual user push messages? Just activate the kPushEnhanceUrl option in Config.swift (by switching the value from false to true) in order to append ?onesignal_push_id=XYZ to your WebView URL. If your WebView URL is https://www.example.org, WebViewGold will call https://www.example.org?onesignal_push_id=XYZ instead. Only the first URL request will get that GET variable, so please save it in a session or in a cookie to access it on your linked pages. An alternative or additional way would be to retrieve & process the information on any page via JavaScript:


<script>
window.location.href = "getonesignalplayerid://";
alert(onesignalplayerid);
</script>


Alternatively, consider turning autoInjectVariable to true in Config.swift to automatically inject this (and other) values into JavaScript without needing to call a URL upfront.




Option 4: Use Firebase Remote Push Notifications

Step 1: Create a Firebase Project
Begin by creating a Firebase project in your Firebase Console. This is a prerequisite for integrating Firebase with your WebViewGold app.

Step 2: Register Your App with Firebase
Once your Firebase project is ready, you can add your WebViewGold app to it by following these steps:

a. Navigate to the project overview page in your Firebase console, then select the iOS icon to start the app registration process.

b. To add a new app to your project, click Add app and select the platform options. When prompted, enter your app's bundle ID into the iOS bundle ID field. This ID is crucial and can be found by:
- Opening your app project in Xcode.
- Selecting the project name at the top of the navigator to access the General tab.
- Your app's bundle ID is listed under the Bundle Identifier field (e.g., com.onlineappcreator.webviewgold).
Ensure you input the exact bundle ID used by your app. This value is permanent once your app is registered with Firebase.

c. Complete the setup by providing the required app information, including:
- App Nickname: A convenience identifier for your reference in the Firebase console.
- App Store ID: Necessary for Firebase Dynamic Links and Google Analytics integration. You can add this later if your app doesn't have one yet.

Step 3: Register Your App
Click Register app to complete the registration process.

Step 4: Download GoogleService-Info.plist
Download this configuration file and replace the placeholder in your WebViewGold project with the downloaded GoogleService-Info.plist file.

Step 5: Activate Firebase in WebViewGold
In the Config.swift file, set the kFirebasePushEnabled variable to true to enable Firebase functionalities.

Step 6: Set Up APN and Sign Your App
Generate an APN key for Firebase, upload it, and then sign your app using the Firebase provisioning profile. For a detailed guide, visit Firebase documentation on iOS certificates.

Step 7: Implement URL Deeplinking (Optional)
For Firebase URL Deeplinking support, add the target URL in a Custom Data field under Additional options (optional), with Key = "url" and Value = {desired URL}.

Add a custom URL for deeplinking purposes in WebView


To subscribe to a Firebase topic, set firebaseTopic in Config.swift to the name of the topic you would like.

Do you want to get each individual subscription ID on your server for further processing and individual user push messages? Just activate the kFirebaseEnhanceUrl option in Config.swift (by switching the value from false to true) in order to append ?firebase_push_id=XYZ to your WebView URL. If your WebView URL is https://www.example.org, WebViewGold will call https://www.example.org?firebase_push_id=XYZ instead. Only your FIRST URL request will get that GET variable, so save it in a session or in a cookie to access it on your linked pages. An alternative or additional way would be to retrieve & process the information on any page via JavaScript:
<script>
window.location.href = "getfirebaseplayerid://";
alert(firebaseplayerid);
</script>


Alternatively, consider turning autoInjectVariable to true in Config.swift to automatically inject this (and other) values into JavaScript without needing to call a URL upfront.




Option 5: Use bubble.io Push Notifications

1. Create a bubble.io app
2. Install the WebViewGold OneSignal Push plugin:
bubble.io WebViewGold OneSignal Push plugin
3. Follow the OneSignal instructions (see above) and the plugin instructions (see here and here).

SDK 风格的实现说明

将此功能视为向 Web 层公开的原生能力:将生产网站或 PWA 作为唯一可信来源,然后使用文档中的 WebViewGold 配置标志、URL 命令和 JavaScript 桥接调用,仅在能够带来价值的地方启用原生 iOS 行为。这种方式让代码库易于维护,因为同一个 Web 应用只需极少的条件逻辑即可同时服务于浏览器、WebViewGold for iOS 以及其他 WebViewGold 平台。

为获得可靠的结果,建议优先使用 HTTPS 端点、稳定的路由名称、在界面中明确的成功/错误状态,以及封装原生调用的小型 JavaScript 辅助函数。例如,使用 jQuery Mobile、Lovable、Base44、Bolt、WordPress、Bubble、自定义 React/Vue/Angular 技术栈或静态 HTML 构建的 Web 应用,可以提供单个按钮或事件处理程序来触发原生 WebViewGold API,同时仍为浏览器提供优雅的回退方案。

  • 推荐的集成模式:检测应用上下文,调用 WebViewGold API,然后在原生回调或路由变更后更新 Web 界面。
  • 测试清单:在真机或打包构建上验证该功能,检查权限和商店审核文案,并确认仅使用浏览器的用户仍能获得有用的回退方案。
  • SEO 优势:让功能页面、路由标题和结构化内容在您的网站上保持可被索引,同时由 WebViewGold 为 iOS 用户提供原生应用外壳。

太忙了?我们替您搭建应用。

我们的团队为您配置、构建并提交 WebViewGold 应用——全程代劳、交付迅速、德国制造。

让我们搭建应用 →

在浏览器中构建

无需 Mac、无需 IDE:WebViewGold Cloud Builder 在线为您配置、构建并上传应用。

了解 Cloud Builder →