Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dpr-dev/a9bf26f43a142c2f49230da9f21526b7 to your computer and use it in GitHub Desktop.
Save dpr-dev/a9bf26f43a142c2f49230da9f21526b7 to your computer and use it in GitHub Desktop.

Revisions

  1. @daominhsangvn daominhsangvn revised this gist Jun 1, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -131,7 +131,7 @@ export default class PushNotificationController extends Component {

    ## Trouble Shooting:
    1. `RNFIRMessaging.h not found`: Select the error project then make following changes
    - Disable `Parallelize Build` in the project schema, Add `React` to the top of targets list
    - Disable `Parallelize Build` in the project schema, Add `React` to the top of targets list (Optional)
    - Set `Always Search User Paths` true
    - Clear everything in `Build Settings > Header Search` and add `"$(SRCROOT)/../../../ios/Pods/Headers/Public"` with `recursive`
    2.
  2. @daominhsangvn daominhsangvn revised this gist Jun 1, 2017. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -130,7 +130,8 @@ export default class PushNotificationController extends Component {
    7. Goes to `Notifications` in Firebase to send notifications to device.

    ## Trouble Shooting:
    1. `RNFIRMessaging.h not found`:
    1. `RNFIRMessaging.h not found`: Select the error project then make following changes
    - Disable `Parallelize Build` in the project schema, Add `React` to the top of targets list
    - Set `Always Search User Paths` true
    - Clear everything in `Build Settings > Header Search` and add `"$(SRCROOT)/../../../ios/Pods/Headers/Public"` with `recursive`
    2.
  3. @daominhsangvn daominhsangvn revised this gist Jun 1, 2017. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -131,7 +131,8 @@ export default class PushNotificationController extends Component {

    ## Trouble Shooting:
    1. `RNFIRMessaging.h not found`:
    - Fix: Add '$(SRCROOT)/../node_modules/react-native-fcm/ios' to header search paths in build settings
    - Set `Always Search User Paths` true
    - Clear everything in `Build Settings > Header Search` and add `"$(SRCROOT)/../../../ios/Pods/Headers/Public"` with `recursive`
    2.
    ```
    Undefined symbols for architecture arm64:
  4. @daominhsangvn daominhsangvn revised this gist May 31, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -144,7 +144,7 @@ clang: error: linker command failed with exit code 1 (use -v to see invocation)
    3. `React/RCTDefines.h` not found
    - Select the error target > Build Settings > Header Search > Remove all values related to React from node_modules
    - Edit the target schema > Build > disable Parallelize build and add React on top of Targets
    4. `RCTBrideModule.h` or whatever using `React/....` is not found, then add following this to `Header Search` of the project: `"$(SRCROOT)/../../../ios/Pods/Headers/Public"`. Remember correct the relative url, `SRCROOT` is where the xcode project is
    ```
    <key>NSCameraUsageDescription</key>
    <string>The app would like to let you make a picture.</string>
  5. @daominhsangvn daominhsangvn revised this gist May 25, 2017. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -145,7 +145,9 @@ clang: error: linker command failed with exit code 1 (use -v to see invocation)
    - Select the error target > Build Settings > Header Search > Remove all values related to React from node_modules
    - Edit the target schema > Build > disable Parallelize build and add React on top of Targets

    ```
    <key>NSCameraUsageDescription</key>
    <string>The app would like to let you make a picture.</string>
    <key>NSPhotoLibraryUsageDescription</key>
    <string>The app would like to let you choose an item from your Photos.</string>
    <string>The app would like to let you choose an item from your Photos.</string>
    ```
  6. @daominhsangvn daominhsangvn revised this gist May 25, 2017. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -143,4 +143,9 @@ clang: error: linker command failed with exit code 1 (use -v to see invocation)
    - The module of `RNFIRMessaging` was not found in `Libraries` folder, run `react-native link` or `rnpm link <module name>` or add manually
    3. `React/RCTDefines.h` not found
    - Select the error target > Build Settings > Header Search > Remove all values related to React from node_modules
    - Edit the target schema > Build > disable Parallelize build and add React on top of Targets
    - Edit the target schema > Build > disable Parallelize build and add React on top of Targets

    <key>NSCameraUsageDescription</key>
    <string>The app would like to let you make a picture.</string>
    <key>NSPhotoLibraryUsageDescription</key>
    <string>The app would like to let you choose an item from your Photos.</string>
  7. @daominhsangvn daominhsangvn revised this gist May 25, 2017. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    1. Add new App in Firebase Console, select iOS and follow exactly instruction.
    1a. In the `GoogleService-Info.json` step, after download the file, open `xCode`, in `Project Navigator` right click `Supporting` folder and select `Add files to ...` then select the downloaded file.
    1a. In the `GoogleService-Info.plist` step, after download the file, open `xCode`, in `Project Navigator` right click `Supporting` folder and select `Add files to ...` then select the downloaded file.
    2. Following this to create `App Id`, `APNs` (.p8) and `Provisioning Profile` for `iOS`: https://firebase.google.com/docs/cloud-messaging/ios/certs
    2a. Add `APN` file (.p8) to Firebase App
    3. Edit `Podfile`, add following below `pod 'Firebase/Core'`: `pod 'Firebase/Messaging'` then `$ pod install` again
    @@ -140,4 +140,7 @@ Undefined symbols for architecture arm64:
    ld: symbol(s) not found for architecture arm64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    ```
    - The module of `RNFIRMessaging` was not found in `Libraries` folder, run `react-native link` or `rnpm link <module name>` or add manually
    - The module of `RNFIRMessaging` was not found in `Libraries` folder, run `react-native link` or `rnpm link <module name>` or add manually
    3. `React/RCTDefines.h` not found
    - Select the error target > Build Settings > Header Search > Remove all values related to React from node_modules
    - Edit the target schema > Build > disable Parallelize build and add React on top of Targets
  8. @daominhsangvn daominhsangvn renamed this gist May 22, 2017. 1 changed file with 16 additions and 2 deletions.
    18 changes: 16 additions & 2 deletions gistfile1.txt → gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    1. Add new App in Firebase Console, select iOS and follow exactly instruction.
    1a. In the `GoogleService-Info.json` step, after download the file, open `xCode`, in `Project Navigator` right click `Supporting` folder and select `Add files to ...` then select the downloaded file.
    2. Following this to create `App Id`, `APNs` and `Provisioning Profile` for `iOS`: https://firebase.google.com/docs/cloud-messaging/ios/certs
    2. Following this to create `App Id`, `APNs` (.p8) and `Provisioning Profile` for `iOS`: https://firebase.google.com/docs/cloud-messaging/ios/certs
    2a. Add `APN` file (.p8) to Firebase App
    3. Edit `Podfile`, add following below `pod 'Firebase/Core'`: `pod 'Firebase/Messaging'` then `$ pod install` again
    4. Install `react-native-fcm` module then `rnpm link react-native-fcm`
    5. Following this https://github.com/evollu/react-native-fcm#shared-steps and this https://github.com/evollu/react-native-fcm#xcode-post-installation-steps
    @@ -126,4 +127,17 @@ export default class PushNotificationController extends Component {
    }
    }
    ```
    7. Goes to `Notifications` in Firebase to send notifications to device.
    7. Goes to `Notifications` in Firebase to send notifications to device.

    ## Trouble Shooting:
    1. `RNFIRMessaging.h not found`:
    - Fix: Add '$(SRCROOT)/../node_modules/react-native-fcm/ios' to header search paths in build settings
    2.
    ```
    Undefined symbols for architecture arm64:
    "_OBJC_CLASS_$_RNFIRMessaging", referenced from:
    objc-class-ref in AppDelegate.o
    ld: symbol(s) not found for architecture arm64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    ```
    - The module of `RNFIRMessaging` was not found in `Libraries` folder, run `react-native link` or `rnpm link <module name>` or add manually
  9. @daominhsangvn daominhsangvn created this gist May 22, 2017.
    129 changes: 129 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,129 @@
    1. Add new App in Firebase Console, select iOS and follow exactly instruction.
    1a. In the `GoogleService-Info.json` step, after download the file, open `xCode`, in `Project Navigator` right click `Supporting` folder and select `Add files to ...` then select the downloaded file.
    2. Following this to create `App Id`, `APNs` and `Provisioning Profile` for `iOS`: https://firebase.google.com/docs/cloud-messaging/ios/certs
    3. Edit `Podfile`, add following below `pod 'Firebase/Core'`: `pod 'Firebase/Messaging'` then `$ pod install` again
    4. Install `react-native-fcm` module then `rnpm link react-native-fcm`
    5. Following this https://github.com/evollu/react-native-fcm#shared-steps and this https://github.com/evollu/react-native-fcm#xcode-post-installation-steps
    6. Write Component to handle Push Notifications:
    ```
    # main.js

    import React, { Component } from 'react';
    import {
    StyleSheet,
    Text,
    TouchableOpacity,
    View
    } from 'react-native';

    import PushNotification from "./PushNotification";

    export default class App extends Component {
    render() {
    return (
    <View style={styles.container}>
    <PushNotification />
    <Text style={styles.welcome}>
    Welcome to Push Notification for React Native!
    </Text>
    </View>
    );
    }
    }

    const styles = StyleSheet.create({
    container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
    },
    welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
    },
    });



    # PushNotification.js
    import React, { Component } from "react";

    import { Platform } from 'react-native';

    import FCM, {FCMEvent, RemoteNotificationResult, WillPresentNotificationResult, NotificationType} from "react-native-fcm";

    export default class PushNotificationController extends Component {
    constructor(props) {
    super(props);
    }

    componentDidMount() {
    FCM.requestPermissions();

    FCM.getFCMToken().then(token => {
    console.log("TOKEN (getFCMToken)", token);
    });

    FCM.getInitialNotification().then(notif => {
    console.log("INITIAL NOTIFICATION", notif)
    });

    this.notificationListner = FCM.on(FCMEvent.Notification, notif => {
    console.log("Notification", notif);
    if(notif.local_notification){
    return;
    }
    if(notif.opened_from_tray){
    return;
    }

    if(Platform.OS ==='ios'){
    //optional
    //iOS requires developers to call completionHandler to end notification process. If you do not call it your background remote notifications could be throttled, to read more about it see the above documentation link.
    //This library handles it for you automatically with default behavior (for remote notification, finish with NoData; for WillPresent, finish depend on "show_in_foreground"). However if you want to return different result, follow the following code to override
    //notif._notificationType is available for iOS platfrom
    switch(notif._notificationType){
    case NotificationType.Remote:
    notif.finish(RemoteNotificationResult.NewData) //other types available: RemoteNotificationResult.NewData, RemoteNotificationResult.ResultFailed
    break;
    case NotificationType.NotificationResponse:
    notif.finish();
    break;
    case NotificationType.WillPresent:
    notif.finish(WillPresentNotificationResult.All) //other types available: WillPresentNotificationResult.None
    break;
    }
    }
    this.showLocalNotification(notif);
    });

    this.refreshTokenListener = FCM.on(FCMEvent.RefreshToken, token => {
    console.log("TOKEN (refreshUnsubscribe)", token);
    });
    }

    showLocalNotification(notif) {
    FCM.presentLocalNotification({
    title: notif.title,
    body: notif.body,
    priority: "high",
    click_action: notif.click_action,
    show_in_foreground: true,
    local: true
    });
    }

    componentWillUnmount() {
    this.notificationListner.remove();
    this.refreshTokenListener.remove();
    }


    render() {
    return null;
    }
    }
    ```
    7. Goes to `Notifications` in Firebase to send notifications to device.