React-native-onesignal: IOS: how to remove notification request on app launch?

Created on 10 May 2019  路  6Comments  路  Source: OneSignal/react-native-onesignal

Description:
I want to delay requesting push notifications. How to do this?

(your description here)

Environment
"react-native-onesignal": "^3.2.12",
I added oneSignal using nom, I have ExpoKit project

I have tried to add this line to AppDelagate.m, but I got Xcode error:

"Property 'oneSignal' not found on object of type 'AppDelegate *'

#import "AppDelegate.h"
#import <React/RCTPushNotificationManager.h>

@implementation AppDelegate

// Put your app delegate methods here. Remember to also call methods from EXStandaloneAppDelegate superclass
// in order to keep Expo working. See example below.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.oneSignal = [[RCTOneSignal alloc] initWithLaunchOptions:launchOptions
                                                           appId:@"your-app-id"
                                                        settings:@{kOSSettingsKeyAutoPrompt : @NO}];

    return [super application:application didFinishLaunchingWithOptions:launchOptions];

}

@end 
Help Wanted iOS

Most helpful comment

Hello,
You shouldn't need to do anything in any of the native files. Everything you need can be done in JS. In your initialization, call OneSignal.init(appId, {kOSSettingsKeyAutoPrompt : false}); and then simply register for push in your own custom timer.

All 6 comments

Hello,
It sounds like you are following the native SDK reference. Please make sure to look at React Native's SDK docs which has a bit of a different init process. This is actually done in your App.js or whatever your root component file is.

@rgomezp yes, I followed that documentation and that exactly how I added One signal push notifications library, everything is in App.js file, my question is how to delay notification permission request in that case? or remove it?

@rgomezp take a look here https://github.com/geektimecoil/react-native-onesignal/issues/108#issuecomment-491276096

Hello,
You shouldn't need to do anything in any of the native files. Everything you need can be done in JS. In your initialization, call OneSignal.init(appId, {kOSSettingsKeyAutoPrompt : false}); and then simply register for push in your own custom timer.

@rgomezp Thanks, I will test it!

@rgomezp Awesome, it works! :)

Fantastic!

Was this page helpful?
0 / 5 - 0 ratings