iOS SDK 7.0+ 高级集成指南
이 콘텐츠는 아직 귀하의 언어로 제공되지 않습니다.
本节提供有关 Pushwoosh iOS SDK 高级集成的信息。
后台模式
Anchor link to要启用此功能,您必须将后台模式添加到您的项目中。
启用后台模式的步骤
Anchor link to- 在 Xcode 中打开您的项目,并在 Project Navigator 中选择它。
- 从左侧面板中选择您的应用程序目标。
- 导航到 Signing & Capabilities 选项卡。
- 单击左上角的 + Capability 按钮。
- 从列表中搜索并选择 Background Modes。
- 在 Background Modes 部分,通过勾选复选框启用 Remote notifications。
完成后,您的应用程序将能够在后台运行时处理推送通知,包括静默通知。
前台模式
Anchor link to默认情况下,当应用程序在前台运行时,Pushwoosh iOS SDK 会显示通知横幅。
您可以通过在代码中(例如,在您的 AppDelegate 中)设置以下布尔标志来控制此行为:
// 设置为 false 以禁用前台通知,设置为 true 以启用Pushwoosh.configure.showPushnotificationAlert = true// 设置为 0 以禁用前台通知,设置为 1 以启用[[Pushwoosh configure] setShowPushnotificationAlert:0];日志级别
Anchor link toPushwoosh iOS SDK 支持以下日志记录级别:
NONE- SDK 不记录任何日志。ERROR- 仅在控制台中显示错误消息。WARNING- 除错误外还显示警告。INFO- 包括信息性消息(默认设置)。DEBUG- 包括详细的调试信息。
默认情况下,日志记录级别设置为 INFO,以确保 SDK 提供相关信息而不会使开发者控制台变得混乱。
要修改日志记录级别,请更新应用程序的 Info.plist 文件中的 Pushwoosh_LOG_LEVEL 键:
<key>Pushwoosh_LOG_LEVEL</key><string>YOUR_LOG_LEVEL</string>或者,您可以使用下面的代码片段更改日志级别:
Pushwoosh.Debug.setLogLevel(.PW_LL_DEBUG)将 YOUR_LOG_LEVEL 替换为所需的级别(例如 DEBUG 或 ERROR)。
自定义 UNNotificationCenterDelegate
Anchor link to如果您想使用自己的 UNNotificationCenterDelegate(例如,用于本地通知),您应该告知 Pushwoosh SDK 以确保其正常运行。您可以通过 Pushwoosh 实例的 notificationCenterDelegateProxy 属性来执行此操作:
Pushwoosh.configure?.notificationCenterDelegateProxy.add(my_delegate)[Pushwoosh.configure.notificationCenterDelegateProxy addNotificationCenterDelegate:my_delegate];然后,在您的委托中实现 UNNotificationCenterDelegate 方法:
func userNotificationCenter( _ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { if (!PWMessage.isPushwooshMessage(notification.request.content.userInfo)) { // 处理您的通知 completionHandler(UNNotificationPresentationOptions.alert) }}
func userNotificationCenter( _ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { if (!PWMessage.isPushwooshMessage(response.notification.request.content.userInfo)) { // 处理您的通知 completionHandler() }}- (void)userNotificationCenter:(UNNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler { if (![PWMessage isPushwooshMessage:notification.request.content.userInfo]) { // 处理您的消息 completionHandler(UNNotificationPresentationOptionAlert); }}
- (void)userNotificationCenter:(UNNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler { if (![PWMessage.isPushwooshMessage:response.notification.request.content.userInfo]) { // 处理您的消息 completionHandler(); }}Pushwoosh 延迟初始化
Anchor link toPushwoosh_LAZY_INITIALIZATION 标志可防止应用程序启动时 Pushwoosh SDK 自动初始化。这使得您可以更好地控制 Pushwoosh SDK 服务的启动时间。
启用此标志后,Pushwoosh SDK 在明确调用 Pushwoosh iOS SDK 方法之前不会启动其服务。
将以下条目添加到 Info.plist 中:
<key>Pushwoosh_LAZY_INITIALIZATION</key><true/>用例
-
受控的 SDK 初始化 – Pushwoosh_LAZY_INITIALIZATION 标志允许延迟 Pushwoosh SDK 的启动,从而更好地控制推送服务的激活时间。
-
延迟推送激活 – 在某些应用程序中,推送通知只应在特定条件下初始化。启用此标志可确保 Pushwoosh SDK 仅在明确请求时启动。
-
用户特定的推送配置 – 某些应用程序可能需要根据用户偏好或帐户设置自定义推送通知设置。通过延迟初始化,Pushwoosh SDK 仅在确定适当的配置后才会启动。
Info.plist 属性完整列表
Anchor link to| 属性 | 描述 | 可能的值 |
|---|---|---|
Pushwoosh_APPID | 为生产版本设置 Pushwoosh 应用程序 ID。 | XXXXX-XXXXX 类型: String |
Pushwoosh_APPID_Dev | 为开发版本设置 Pushwoosh 应用程序 ID。 | XXXXX-XXXXX 类型: String |
Pushwoosh_SHOW_ALERT | 显示通知前台提醒。 | YES (默认) / NO 类型: Boolean |
Pushwoosh_ALERT_TYPE | 设置通知提醒样式。 | BANNER (默认) / ALERT / NONE 类型: String |
Pushwoosh_BASEURL | 覆盖 Pushwoosh 服务器基础 URL。 | https://cp.pushwoosh.com/json/1.3/ (默认) 类型: String |
Pushwoosh_AUTO_ACCEPT_DEEP_LINK_FOR_SILENT_PUSH | 如果为 YES,在静默推送中收到的 Deep Link 将被自动处理。 | YES (默认) / NO 类型: Boolean |
Pushwoosh_ALLOW_SERVER_COMMUNICATION | 允许 SDK 向 Pushwoosh 服务器发送网络请求。 | YES (默认) / NO 类型: Boolean |
Pushwoosh_ALLOW_COLLECTING_DEVICE_DATA | 允许 SDK 收集设备数据(操作系统版本、区域设置和型号)并发送到服务器。 | YES (默认) / NO 类型: Boolean |
Pushwoosh_ALLOW_COLLECTING_DEVICE_OS_VERSION | 允许 SDK 收集设备的操作系统版本并发送到服务器。 | YES (默认) / NO 类型: Boolean |
Pushwoosh_ALLOW_COLLECTING_DEVICE_LOCALE | 允许 SDK 收集设备区域设置并发送到服务器。 | YES (默认) / NO 类型: Boolean |
Pushwoosh_ALLOW_COLLECTING_DEVICE_MODEL | 允许 SDK 收集设备型号并发送到服务器。 | YES (默认) / NO 类型: Boolean |
Pushwoosh_LOG_LEVEL | Pushwoosh SDK 日志记录级别。有关详细信息,请参阅控制日志级别。 | NONE / ERROR / WARNING / INFO (默认) / DEBUG / VERBOSE 类型: String |
Pushwoosh_PURCHASE_TRACKING_ENABLED | 允许 SDK 跟踪应用内购买。Customer Journey Builder 需要此功能。 | YES / NO (默认) 类型: Boolean |