React-native-firebase: requestPermissions is not a function , so with subscribeToTopic

Created on 27 Mar 2018  路  7Comments  路  Source: invertase/react-native-firebase

Development Operating System:
Xcode Version : 9.2
Environment:
iOS
Application Target Platform:
macOS Sierra
"react-native": "^0.54.3",
"react-native-firebase": "^4.0.0-rc.2",

Issue:
its happening when I migrated from 3.3.1 to 4.0.0-rc.2, however, I made all changes carefully into appdelegate.m , appdelegate.h

PodLock file

````
PODS:

  • BoringSSL (10.0):

    • BoringSSL/Implementation (= 10.0)

    • BoringSSL/Interface (= 10.0)

  • BoringSSL/Implementation (10.0):

    • BoringSSL/Interface (= 10.0)

  • BoringSSL/Interface (10.0)
  • Firebase/Auth (4.11.0):

    • Firebase/Core

    • FirebaseAuth (= 4.5.0)

  • Firebase/Core (4.11.0):

    • FirebaseAnalytics (= 4.1.0)

    • FirebaseCore (= 4.0.18)

  • Firebase/Database (4.11.0):

    • Firebase/Core

    • FirebaseDatabase (= 4.1.5)

  • Firebase/Firestore (4.11.0):

    • Firebase/Core

    • FirebaseFirestore (= 0.10.4)

  • Firebase/Messaging (4.11.0):

    • Firebase/Core

    • FirebaseMessaging (= 2.1.1)

  • Firebase/Storage (4.11.0):

    • Firebase/Core

    • FirebaseStorage (= 2.1.3)

  • FirebaseAnalytics (4.1.0):

    • FirebaseCore (~> 4.0)

    • FirebaseInstanceID (~> 2.0)

    • GoogleToolboxForMac/NSData+zlib (~> 2.1)

    • nanopb (~> 0.3)

  • FirebaseAuth (4.5.0):

    • FirebaseAnalytics (~> 4.1)

    • GoogleToolboxForMac/NSDictionary+URLArguments (~> 2.1)

    • GTMSessionFetcher/Core (~> 1.1)

  • FirebaseCore (4.0.18):

    • GoogleToolboxForMac/NSData+zlib (~> 2.1)

  • FirebaseDatabase (4.1.5):

    • FirebaseAnalytics (~> 4.1)

    • FirebaseCore (~> 4.0)

    • leveldb-library (~> 1.18)

  • FirebaseFirestore (0.10.4):

    • FirebaseAnalytics (~> 4.1)

    • FirebaseCore (~> 4.0)

    • gRPC-ProtoRPC (~> 1.0)

    • leveldb-library (~> 1.18)

    • Protobuf (~> 3.5)

  • FirebaseInstanceID (2.0.10):

    • FirebaseCore (~> 4.0)

  • FirebaseMessaging (2.1.1):

    • FirebaseAnalytics (~> 4.1)

    • FirebaseCore (~> 4.0)

    • FirebaseInstanceID (~> 2.0)

    • GoogleToolboxForMac/Logger (~> 2.1)

    • Protobuf (~> 3.5)

  • FirebaseStorage (2.1.3):

    • FirebaseAnalytics (~> 4.1)

    • FirebaseCore (~> 4.0)

    • GTMSessionFetcher/Core (~> 1.1)

  • GoogleToolboxForMac/DebugUtils (2.1.3):

    • GoogleToolboxForMac/Defines (= 2.1.3)

  • GoogleToolboxForMac/Defines (2.1.3)
  • GoogleToolboxForMac/Logger (2.1.3):

    • GoogleToolboxForMac/Defines (= 2.1.3)

  • GoogleToolboxForMac/NSData+zlib (2.1.3):

    • GoogleToolboxForMac/Defines (= 2.1.3)

  • GoogleToolboxForMac/NSDictionary+URLArguments (2.1.3):

    • GoogleToolboxForMac/DebugUtils (= 2.1.3)

    • GoogleToolboxForMac/Defines (= 2.1.3)

    • GoogleToolboxForMac/NSString+URLArguments (= 2.1.3)

  • GoogleToolboxForMac/NSString+URLArguments (2.1.3)
  • gRPC (1.10.0):

    • gRPC-RxLibrary (= 1.10.0)

    • gRPC/Main (= 1.10.0)

  • gRPC-Core (1.10.0):

    • gRPC-Core/Implementation (= 1.10.0)

    • gRPC-Core/Interface (= 1.10.0)

  • gRPC-Core/Implementation (1.10.0):

    • BoringSSL (~> 10.0)

    • gRPC-Core/Interface (= 1.10.0)

    • nanopb (~> 0.3)

  • gRPC-Core/Interface (1.10.0)
  • gRPC-ProtoRPC (1.10.0):

    • gRPC (= 1.10.0)

    • gRPC-RxLibrary (= 1.10.0)

    • Protobuf (~> 3.0)

  • gRPC-RxLibrary (1.10.0)
  • gRPC/Main (1.10.0):

    • gRPC-Core (= 1.10.0)

    • gRPC-RxLibrary (= 1.10.0)

  • GTMSessionFetcher/Core (1.1.14)
  • leveldb-library (1.20)
  • nanopb (0.3.8):

    • nanopb/decode (= 0.3.8)

    • nanopb/encode (= 0.3.8)

  • nanopb/decode (0.3.8)
  • nanopb/encode (0.3.8)
  • Protobuf (3.5.0)
  • QBImagePickerController (3.4.0)
  • RSKImageCropper (2.0.0)

DEPENDENCIES:

  • Firebase/Auth
  • Firebase/Core
  • Firebase/Database
  • Firebase/Firestore
  • Firebase/Messaging
  • Firebase/Storage
  • QBImagePickerController
  • RSKImageCropper

SPEC CHECKSUMS:
BoringSSL: ************** ( I hide intentionally )
Firebase:
************** ( I hide intentionally )
FirebaseAnalytics: ************** ( I hide intentionally )
FirebaseAuth:
************** ( I hide intentionally )
FirebaseCore: ************** ( I hide intentionally )
FirebaseDatabase:
************** ( I hide intentionally )
FirebaseFirestore: ************** ( I hide intentionally )
FirebaseInstanceID:
************** ( I hide intentionally )
FirebaseMessaging: ************** ( I hide intentionally )
FirebaseStorage:
************** ( I hide intentionally )
GoogleToolboxForMac: ************** ( I hide intentionally )
gRPC:
************** ( I hide intentionally )
gRPC-Core: ************** ( I hide intentionally )
gRPC-ProtoRPC:
************** ( I hide intentionally )
gRPC-RxLibrary: ************** ( I hide intentionally )
GTMSessionFetcher:
************** ( I hide intentionally )
leveldb-library: ************** ( I hide intentionally )
nanopb:
************** ( I hide intentionally )
Protobuf: ************** ( I hide intentionally )
QBImagePickerController:
************** ( I hide intentionally )
RSKImageCropper: *************** ( I hide intentionally )

PODFILE CHECKSUM: *************** ( I hide intentionally )

COCOAPODS: 1.4.0
````

JS code
````
firebase.messaging().requestPermissions()
.then(() => {
// User has authorised
console.log('the notification')
})
.catch(error => {
// User has rejected permissions
});
...
...

firebase.messaging().subscribeToTopic('all')
.then(function(response) { console.log('Successfully subscribed to topic:', response);
}) .catch(function(error) {
console.log('Error subscribing to topic:', error);
});

````

screen shot 2018-03-27 at 11 04 21 pm
screen shot 2018-03-27 at 11 01 02 pm

Appdelegate.h
````

import

@interface AppDelegate : UIResponder
@property (nonatomic, strong) UIWindow *window;
@end
````

Appdelegate.m
````

import "AppDelegate.h"

import

import "RNFirebaseNotifications.h"

import "RNFirebaseMessaging.h"

import

import

@implementation AppDelegate

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    [FIRApp configure];
    [RNFirebaseNotifications configure];

    NSURL *jsCodeLocation;

    jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];

    RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
    moduleName:@"myapp"
    initialProperties:nil
    launchOptions:launchOptions];
    rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];

    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    UIViewController *rootViewController = [UIViewController new];
    rootViewController.view = rootView;
    self.window.rootViewController = rootViewController;
    [self.window makeKeyAndVisible];

    return YES;
    }

  • (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
    [[RNFirebaseNotifications instance] didReceiveLocalNotification:notification];
    }

  • (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo
    fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{
    [[RNFirebaseNotifications instance] didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
    }

  • (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
    [[RNFirebaseMessaging instance] didRegisterUserNotificationSettings:notificationSettings];
    }

@end
````

Podfile
````
# Uncomment the next line to define a global platform for your project
platform :ios, '8.0'

target 'myapp' do
# Uncomment the next line if you're using Swift or would like to use dynamic frameworks
# use_frameworks!

# Pods for myapp

pod 'RSKImageCropper'
pod 'QBImagePickerController'

pod 'Firebase/Core'
pod 'Firebase/Database'
pod 'Firebase/Messaging'
pod 'Firebase/Storage'
pod 'Firebase/Firestore'

pod 'Firebase/Auth'

target 'myappTests' do
inherit! :search_paths
# Pods for testing
end

end
````

Most helpful comment

@amitbravo In response to each of your issues:

1) requestPermissions() is now requestPermission() to match the web SDK.
2) subscribeToTopic() is currently not a Promise, but will be changed for the next release candidate so that it is

All 7 comments

@amitbravo In response to each of your issues:

1) requestPermissions() is now requestPermission() to match the web SDK.
2) subscribeToTopic() is currently not a Promise, but will be changed for the next release candidate so that it is

can I still use subscribeToTopic() without .then(.... ?

You can indeed

I'm facing the exact same issue with the syntax given in the docs.

Here is the description -

Package.json -

"react-native-firebase": "4.0.0-rc.3",

Usage -

    componentDidMount(): void {
        this.connectToFirebase();
    }

    connectToFirebase = (): void => {
        // I've tried using this with async-await, tried 
        // resolving the promise using .then. I also tried calling hasPermission. Same issue. 
        firebase.messaging().requestPermission(); 

        registerNotificationListener(this.onNotification);
        registerMessageListener(this.onMessage);
    }

Error -
When calling requestPermission directly (Without resolving the promise) -
screen shot 2018-04-03 at 11 40 39 am

When requestPermission is called using async-await -
screen shot 2018-04-03 at 11 39 38 am

When hasPermission is called -
screen shot 2018-04-03 at 11 36 27 am

Is there something I might have missed? Help needed.

I have run into the same issue as @omkarjoshi-cc regarding hasPermission

@danielmilner @omkarjoshi-cc Using old version?

https://github.com/invertase/react-native-firebase/releases/tag/v4.0.0

@setkyar Yeah, I haven't upgraded to v4 yet. I'll try using v4 and report if the issue still persists.

Was this page helpful?
0 / 5 - 0 ratings