Skip to content
This repository has been archived by the owner on Jan 14, 2025. It is now read-only.

Local notification showing in console, but not appearing on device #898

Closed
vemundeldegard opened this issue Oct 10, 2018 · 6 comments
Closed
Labels

Comments

@vemundeldegard
Copy link

vemundeldegard commented Oct 10, 2018

Hello!

I am trying to test out Push Notification in my app. I can see the notification in the console like this:

'NOTIFICATION:', { foreground: true,
  userInteraction: false,
  message: 'My Notification Message',
  data: {},
  badge: 10,
  alert: 'My Notification Message',
  sound: 'default',
  finish: [Function: finish] }

But nothing appears on the device. I am debugging on iPhone X with iOS 11.

I have also tried on my own iPhone X with iOS 12, but then I run into this issue that I can't seem to solve. .

I have linked everything according to the guide from React Native, as well as linking manually.

App.js

import PushNotification from 'react-native-push-notification';
import {PushNotificationIOS} from 'react-native';

PushNotification.configure({

  onRegister: function(token) {
    console.log( 'TOKEN:', token );

  },

  onNotification: function(notification) {

    console.log( 'NOTIFICATION:', notification );

    // process the notification
    // required on iOS only
    notification.finish(PushNotificationIOS.FetchResult.NoData);
  },

  permissions: {
    alert: true,
    badge: true,
    sound: true
  },

  popInitialNotification: true,
  requestPermissions: true,

});

In my component I try firing an local notification like this:

handleOnPress = () => {
     PushNotification.localNotification({
       title: "My Notification Title", // (optional)
        message: "My Notification Message", // (required)
        playSound: true, // (optional) default: true
        soundName: 'default', // (optional) Sound to play when the notification is shown. Value of 'default' plays the default sound. It can be set to a custom sound such as 'android.resource://com.xyz/raw/my_sound'. It will look for the 'my_sound' audio file in 'res/raw' directory and play it. default: 'default' (default sound is played)
        number: 10, // (optional) Valid 32 bit integer specified as string. default: none (Cannot be zero)
        repeatType: 'day', // (optional) Repeating interval. Check 'Repeating Notifications' section for more info.
        actions: '["Yes", "No"]',  // (Android only) See the doc for notification actions to know more
     });
   };

AppDelegate.m:

/**
 * Copyright (c) 2015-present, Facebook, Inc.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

 @import GooglePlaces;




#import "AppDelegate.h"
#import <GoogleMaps/GoogleMaps.h>
#import <React/RCTPushNotificationManager.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>


@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  [GMSPlacesClient provideAPIKey:@"AIzaSyC5Ng4S3l3w8uJtDwpCrcqa_2-ErGJDVfQ"];
  [GMSServices provideAPIKey:@"AIzaSyC5Ng4S3l3w8uJtDwpCrcqa_2-ErGJDVfQ"];
  NSURL *jsCodeLocation;

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

  RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                      moduleName:@"Green"
                                               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;
  
  
  
}
// Required to register for notifications
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
  [RCTPushNotificationManager didRegisterUserNotificationSettings:notificationSettings];
}
// Required for the register event.
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
  [RCTPushNotificationManager didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
// Required for the notification event. You must call the completion handler after handling the remote notification.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
  [RCTPushNotificationManager didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}
// Required for the registrationError event.
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
  [RCTPushNotificationManager didFailToRegisterForRemoteNotificationsWithError:error];
}
// Required for the localNotification event.
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
  [RCTPushNotificationManager didReceiveLocalNotification:notification];
}
@end
@bonlemuel
Copy link

+1 same result for me

@mazenchami
Copy link

+1

@glocore
Copy link

glocore commented Nov 26, 2018

I'm facing the same issue. It works fine on Android, but not on iOS. Using version 3.1.2

@verybluebot
Copy link

@vemundeldegard on IOS you can't get notifications when the app in in foreground (opened) try to send a scheduled notification for 5 seconds and close the device once you trigger it, should work..
That explains why it worked for you on android
also you can get local and scheduled notifications on a simulator

@1b0t
Copy link

1b0t commented Feb 7, 2019

@verybluebot it is certainly possible on iOS it's just not supported out of the box.

#919

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions.

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

No branches or pull requests

6 participants