Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permission asked automatically when the app starts #108

Closed
mtt87 opened this issue Nov 9, 2016 · 12 comments
Closed

Permission asked automatically when the app starts #108

mtt87 opened this issue Nov 9, 2016 · 12 comments

Comments

@mtt87
Copy link

mtt87 commented Nov 9, 2016

For some reason the popup asking permission for the push notifications is showing automatically when the app is opened for the first time even if I'm not calling OneSignal anywhere inside my JS code.
Is this the expected behaviour?
I'd like to be able to ask for permission inside the app at some point, not on the first loading (which is very bad).

Package version:

"react-native": "0.37.0",
"react-native-onesignal": "^1.2.3",

app.js

import React from 'react';
import { Text } from 'react-native';
// import OneSignal from 'react-native-onesignal';

// const pendingNotifications = [];

// const handleNotification = (notification) => {
//   console.log(pendingNotifications);
//   alert(notification.message);
// };

// OneSignal.configure({
//   onIdsAvailable(device) {
//     console.log('UserId = ', device.userId);
//     console.log('PushToken = ', device.pushToken);
//   },
//   onNotificationOpened(message, data, isActive) {
//     const notification = {
//       message,
//       data,
//       isActive,
//     };
//     pendingNotifications.push(notification);
//     handleNotification(notification);
//   },
//   enableInAppAlertNotification: true,
// });
const WelcomeScreen = () => <Text>Hello world</Text>;
export default WelcomeScreen;
@mtt87
Copy link
Author

mtt87 commented Nov 16, 2016

Anyone here can give me some hint to where to start debugging? (given the fact that I'm not iOS dev but JS dev, I'm not much familiar with Xcode/Swift/Obj-c)

Thank you

@psyzz
Copy link

psyzz commented Nov 19, 2016

@mtt87 in your AppDelegate.m: add "autoRegister: false":

self.oneSignal = [[RCTOneSignal alloc] initWithLaunchOptions:launchOptions appId:@"<app id>" autoRegister: false];

then in your js when you want to ask permission:

OneSignal.registerForPushNotifications();

@mtt87
Copy link
Author

mtt87 commented Nov 20, 2016

@arshavinho seems like it worked, the permission is now asked when I trigger
OneSignal.registerForPushNotifications();

I do a double check and see if the notifications are working fine and then I think I can add this to README since it's never mentioned.

@mtt87
Copy link
Author

mtt87 commented Nov 21, 2016

Confirmed! Works like a charm adding autoRegister: false! 👍

@goldengecko
Copy link

They have changed the API and now you have to pass a dictionary instead:

  self.oneSignal = [[RCTOneSignal alloc] initWithLaunchOptions:launchOptions
                                                         appId:@"your-app-id"
                                                      settings:@{kOSSettingsKeyAutoPrompt : @NO}];

@Luckygirlllll
Copy link

@goldengecko When I'm adding this line of code to AppDelegate.m, I'm getting this Xcode error: "Property 'oneSignal' not found on object of type 'AppDelegate *'". What should I do?

@Luckygirlllll
Copy link

Luckygirlllll commented May 10, 2019

Here is how my AppDelegate.m file look like (I have ExpoKit project):

#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

@goldengecko
Copy link

You haven't declared that variable anywhere. Suggest @synthesize oneSignal = _oneSignal;

@Luckygirlllll
Copy link

@goldengecko If I'm adding @synthesize oneSignal = _oneSignal; I'm getting an error Property implementation must have its declaration in interface 'AppDelegate' or one of its extensions

@goldengecko
Copy link

Yes, you would need to declare it in the header @property (strong, nonatomic) RCTOneSignal* oneSignal; and have the synthesize in the implementation. Just the normal style of variable handling

@champrocks3190
Copy link

any suggestion for Android SDK i am facing the same.

@MaganAnkur
Copy link

I am not using OneSignal but still getting the same issue, Any idea how to solve?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants