我正在尝试将OneSignal集成到我的应用中。
我想要的是当用户点击通知以模态方式呈现所需的ViewController时。我在handleNotificationAction
中实现了打开VC逻辑,同时启用了OneSignal。
问题是OneSignal仍然打开它的WebView,我不希望它。有没有办法在用户点击通知时禁用打开WebView?
let onesignalInitSettings = [kOSSettingsKeyAutoPrompt: false]
OneSignal.initWithLaunchOptions(launchOptions,
appId: "myAppID",
handleNotificationAction: { result in
guard let payload = result?.notification.payload else { return }
guard let additionalData = payload.additionalData else { return }
guard let venueID = additionalData["internal"] as? String else { return }
DispatchQueue.main.async {
self.showVenueDetails(venueID)
}
},
settings: onesignalInitSettings)
OneSignal.inFocusDisplayType = .notification
OneSignal.promptForPushNotifications(userResponse: { accepted in
print("User accepted notifications: \(accepted)")
})
答案 0 :(得分:3)
是的,将vagrant ssh
添加到您的kOSSettingsKeyInAppLaunchURL: false
。这将在默认浏览器中打开URL,而不是onesignalInitSettings
。
如果要显示自定义视图,请不要在有效内容中使用URL参数。而是在其他数据中使用自定义键值对。
答案 1 :(得分:1)
对于 OneSignal SDK 3.x.x
按照 OneSignal 的建议,将以下键添加到项目的 info.plist:
OneSignal_suppress_launch_urls = true
对于 OneSignal SDK 版本 2.x.x
将 kOSSettingsKeyInAppLaunchURL: false
添加到 OneSignal 的 initSetting
答案 2 :(得分:0)
在项目中搜索initOneSignal。设置准参数传递
kOSSettingsKeyInAppLaunchURL: @false
- (void)initOneSignal {
[OneSignal setValue:@"react" forKey:@"mSDKType"];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didBeginObserving) name:@"didSetBridge" object:nil];
[OneSignal initWithLaunchOptions:nil appId:nil handleNotificationReceived:^(OSNotification* notification) {
[self handleRemoteNotificationReceived:[notification stringify]];
} handleNotificationAction:^(OSNotificationOpenedResult *result) {
if (!RCTOneSignal.sharedInstance.didStartObserving)
coldStartOSNotificationOpenedResult = result;
else
[self handleRemoteNotificationOpened:[result stringify]];
} settings:@{@"kOSSettingsKeyInOmitNoAppIdLogging" : @true, kOSSettingsKeyAutoPrompt : @false, kOSSettingsKeyInAppLaunchURL: @false}]; //default autoPrompt to false since init will be called again
didInitialize = false;
}