You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

升级OneSignal iOS 1.13.3至2.8.2后遇代码错误,寻求技术帮助

Fixing OneSignal iOS SDK 2.8.2 Upgrade Errors

Hey there, let's work through those errors you ran into after upgrading from OneSignal SDK 1.13.3 to 2.8.2. The API changed quite a bit between these versions, so your old code needs some targeted adjustments:

1. "Argument passed to call that takes no arguments" (Initialization Error)

In SDK 1.x, you initialized OneSignal with a constructor that accepted launch options, app ID, and a notification handler. But in 2.x, this constructor was completely removed—instead, you configure OneSignal using static methods and set up notification handling via dedicated closures.

Replace your old initialization code with this updated version:

// Set your app ID first
OneSignal.setAppId(appID)
// Pass launch options if your app relies on them
OneSignal.setLaunchOptions(launchOptions)

// Handle notifications received while the app is active in the foreground
OneSignal.notificationWillShowInForeground = { notification in
    // Map the new notification object to your existing handler logic
    let userInfo = notification.payload.additionalData ?? [:]
    NotificationHandler.handleNotification(userInfo: userInfo, appWasActive: true)
}

// Optional: Add logic to handle notifications when the user taps on them
OneSignal.notificationOpened = { result in
    let userInfo = result.notification.payload.additionalData ?? [:]
    NotificationHandler.handleNotification(userInfo: userInfo, appWasActive: false)
}

The core change here is that 2.x uses static configuration methods (setAppId, setLaunchOptions) instead of a constructor, and notification handling is managed via closure properties rather than passing a handler during initialization.

2. "Type 'OneSignal' has no member 'defaultClient'"

The defaultClient() method was deprecated and removed in 2.x—all SDK operations now use static methods or properties directly on the OneSignal class.

Your old line:

OneSignal.defaultClient().enable(inAppAlertNotification: false)

Replace it with this 2.x equivalent to disable in-app alert notifications:

OneSignal.inAppMessagesEnabled = false

If you were targeting a specific type of in-app alert, you can cross-reference the 2.8.2 SDK docs for more granular controls, but this line replicates the core behavior of disabling in-app alert notifications.


内容的提问来源于stack exchange,提问作者Igor Jorin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:50:13