aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.4k stars 2.11k forks source link

No endpoint are registered in pinpoint campaign. #1415

Closed goodryanboy closed 5 years ago

goodryanboy commented 5 years ago

I cant send push notification through campaign in pinpoint but I can send direct message through device token. Help me solved this issue i installed all the project needed for this porject

here is my setup

`import` Amplify, { I18n } from 'aws-amplify';
import Analytics from '@aws-amplify/analytics';
import PushNotification from '@aws-amplify/pushnotification';
Analytics.configure(aws_export);
PushNotification.configure(aws_export);

 componentDidMount(){
    // get the notification data
    Analytics.record({name: 'App Mount last'});
    PushNotification.onNotification((notification) => {
      // Note that the notification object structure is different from Android and IOS
      console.warn('in app notification', notification);

      // required on iOS only (see fetchCompletionHandler docs: https://facebook.github.io/react-native/docs/pushnotificationios.html)
      //notification.finish(PushNotificationIOS.FetchResult.NoData);
    });

    // get the registration token
    PushNotification.onRegister((token) => {
      console.warn('in app registration', token);
      Analytics.updateEndpoint({
          UserId: "Z1Y2X3W4ABC12345A",
          OptOut: "NONE",
      });
    });

  }
`
this is the version i use
`"@aws-amplify/pushnotification": "^1.0.4",
    "aws-amplify": "^1.0.5",
    "aws-amplify-react-native": "^1.0.5",
    "firebase": "4.6.2",
    "mobx": "4.3.0",
    "mobx-react": "5.1.2",
    "react": "16.3.1",
    "react-native": "0.55.4",`

but i can see some endpoint in the analytics but there is nothing in the targetable endpoints aws pinpoint

powerful23 commented 5 years ago

@goodryanboy you need to configure the Auth module in order to get a valid AWS credentials for the Pinpoint service. You can call Amplify.configure() or Auth.configure(). Also you could open the debug mode to provide more info by put window.LOG_LEVEL='DEBUG' in the code.

goodryanboy commented 5 years ago

@powerful23 I already have the Amplify.configure() in my code. Sorry that i dont include it in the documentation. Do it require that the region of the pinpoint must be the same with the region of the Amazon Cognito? because i have a different region . Thank you

goodryanboy commented 5 years ago

Thank you I got it Already,,, Its the Policy errror, I did not update my policy

pmd30011991 commented 5 years ago

@goodryanboy : can you tell me what policy I need, I also get this issue

darreko commented 5 years ago

@goodryanboy @pmd30011991 I'm also having issues not seeing the endpoints and not receiving push notifications. Any help would be awesome!

bernhardt1 commented 5 years ago

@goodryanboy Which policy did you update? I just gave my cognito users admin access and I'm still not seeing them in the pinpoint segments.

goodryanboy commented 5 years ago

@goodryanboy Which policy did you update? I just gave my cognito users admin access and I'm still not seeing them in the pinpoint segments.

@goodryanboy @pmd30011991 I'm also having issues not seeing the endpoints and not receiving push notifications. Any help would be awesome!

@goodryanboy : can you tell me what policy I need, I also get this issue

ahm can you provide the version of your amplify cause last the last version I use it needed to configure the policy manually but the latest version it doesnt required and it works well.

but how I solve last issue is this , I attach a policy called "mobiletargeting:UpdateEndpoint" to the roles that I am using here is the full policy you can copy paste it directly. { "Version": "2012-10-17", "Statement": [ { "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ "mobiletargeting:CreateCampaign", "mobiletargeting:CreateSegment", "mobiletargeting:GetCampaigns", "mobiletargeting:GetSegment", "mobiletargeting:UpdateEndpointsBatch", "mobiletargeting:GetEndpoint", "mobiletargeting:GetApplicationSettings", "mobiletargeting:UpdateEndpoint" ], "Resource": "*" } ] }

the important action is the "mobiletargeting:UpdateEndpoint" hope it helps

bernhardt1 commented 5 years ago

@goodryanboy thanks for the advice. My policies are set correctly after all.

Debugging in the app shows I'm using the correct user pool as well. I'm also able to send a test message to the device using the token being generated by PushNotification.onRegister.

The device is also able to send analytic events which I can see in the pinpoint console.

I was finally able to get the device to show up as an eligible endpoint by updating its analytic info: Analytics.updateEndpoint({...}). However, I'm still not seeing the notification come through to the device (nothing shows up in the logging with Logger.LOG_LEVEL = 'DEBUG'; either.

Not sure how to debug from here.

"dependencies": { "@aws-amplify/pushnotification": "^1.0.19", "aws-amplify": "^1.1.10", "aws-amplify-react-native": "^2.0.8", }

goodryanboy commented 5 years ago

@bernhardt1 Your Welcome.. thats the same issue I experienced last time I can just work it through test message but in the campaign I can send notification but cant recieved.

I also do the Analytics.updateEndpoint({...}) but still not works, but when I try to use Logger.LOG_LEVEL = 'DEBUG';
I see some errors but I cant remember whats the error but the solution is to update my policy under the unauthenticated user role. Where did you attach your policy? is your user logged in or not? and what platform did you use is it ios or android.

here is my dependencies "dependencies": { "@aws-amplify/pushnotification": "^1.0.17", "aws-amplify": "^1.1.9", "aws-amplify-react-native": "^1.0.5", "react": "16.3.1", "react-native": "0.55.4", },

bernhardt1 commented 5 years ago

@goodryanboy thanks again

tldr; it was the policy after all. I needed to create a user group & apply the proper role for my auth users in the user pool.

my user is logged in & authenticated. I attached my policy to both the auth and unauthed users of the apps cognito pool.

Your question about where it was attached just saved me though!

It seems like the non-federated identity users do not get the proper policies attached. I had to create a user group under user pool -> target_app -> users & groups. You can then attach a policy to the group and add users to it.

Now I just need to figure out android :/

here's my dependencies incase someone else runs into this:

  "dependencies": {
    "@aws-amplify/pushnotification": "^1.0.19",
    "aws-amplify": "^1.1.10",
    "aws-amplify-react-native": "^2.0.8",
    "expo": "^31.0.2",
    "expokit": "^31.0.2",
    "react": "16.5.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-31.0.0.tar.gz"
  },
goodryanboy commented 5 years ago

@bernhardt1 Your always welcome.

Im glad that Im able to help. So its working in ios but not android?

bernhardt1 commented 5 years ago

@goodryanboy that's right. My android build problems are outside the scope of this thread though. This issue describes the problems. https://github.com/aws-amplify/amplify-js/issues/1308#issuecomment-445080168

goodryanboy commented 5 years ago

@bernhardt1 just try this change your com.firebase package inside the pushnotification dependencies in the @aws/amplify node_modules from this compile 'com.firebase:firebase-jobdispatcher:0.6.0' to this to this compile 'com.firebase:firebase-jobdispatcher-with-gcm-dep:0.6.0'

try to read this maybe it could help https://medium.com/@suchydan/how-to-solve-google-play-services-version-collision-in-gradle-dependencies-ef086ae5c75f

bernhardt1 commented 5 years ago

@goodryanboy that worked great, thanks again.

Did you ran into problems having the push notification display on android? my endpoint shows up in the pinpoint campaign segment + I'm able to successfully send a notification using the test message in FCM.

The notification just doesn't show up when I send it through pinpoint (both test messages and a campaign). The test message says it was successful "Message sent Successfully sent push message" but it never shows on the android device. All app permissions are turned on and allowed.

goodryanboy commented 5 years ago

@bernhardt1 your welcome.

When you send the notification, is the app in foreground or background? because if the app is in foreground mode the notification wont show up but your app will recieve the notification. If its in background it will show up the notification. try this PushNotification.onNotification((notification) => { console.warn(notification) }

if you get warning it means that the notification is working

bernhardt1 commented 5 years ago

@goodryanboy hmmm this one is trickier. Your recommendations didn't work.

I've tried logging the notification with the app in foreground, but there is nothing coming through into logs. As you said, this must mean that the device is not receiving the notification at all. This seems odd because the FCM test message goes through just fine.

I tried adding logging into the PushNotification file to check if the notification is coming through at all. It is not.

The other functions in PushNotification seem to be working properly. The configuration, androidInitialization, and onRegister call all come through. The pinpoint service is configured and other analytic events are successfully recorded. Additionally, the ios app receives push notifications just fine.

I can't think of any way to debug this problem after checking all of this. I'm going to start a fresh project and see if I can get android notifications working there...

goodryanboy commented 5 years ago

ohhh But you can get notification using the deviceTOken?

bernhardt1 commented 5 years ago

@goodryanboy I can get a notification when using the google FCM test message console so I know my registration token is correct. I haven't been able to get any notifications from pinpoint though (tried both test messaging and creating a campaign).

I created a fresh app and went through the steps to initialize amplify + push notifications as described in the docs: https://aws-amplify.github.io/docs/js/push-notifications.

Even in a fresh project I recreated the same issue. It almost seems like an aws policy problem but the notifications are still working on ios.

If you have any other suggestions that would be great. Otherwise I'll update when/if I find a solution.

goodryanboy commented 5 years ago

If you try Logger.LOG_LEVEL = 'DEBUG'; whats the output can you send me? and also did you add the api key correctly for the FCM in your pinpoint? can you show me your code?

bernhardt1 commented 5 years ago

@goodryanboy I double checked the FCM api key in pinpoint and it is set correctly.

Here is a code share with the logging from the app initially loading: https://codeshare.io/5RQxqW

Here's the code:

import React from 'react';
import { Linking, Button, StyleSheet, Text, View, PushNotificationIOS, Platform } from 'react-native';

import { withAuthenticator } from 'aws-amplify-react-native'

import { Logger } from 'aws-amplify';
import Auth from '@aws-amplify/auth';
import Analytics from '@aws-amplify/analytics';
import PushNotification from '@aws-amplify/pushnotification';

import config from './aws-exports'

Auth.configure(config);
Analytics.configure(config);
PushNotification.configure(config);
Logger.LOG_LEVEL = 'DEBUG';

class App extends React.Component {
  constructor(props) {
    super(props);
    this.handleAnalyticsClick = this.handleAnalyticsClick.bind(this);
    this.state = {resultHtml: <Text></Text>, eventsSent: 0};
  }

  componentDidMount() {
    if (Platform.OS === "ios") {
      PushNotification.initializeIOS();
    } else {
      console.log("initializing android");
      PushNotification.initializeAndroid();
    }

    Analytics.updateEndpoint({
      // address: 'dYhXgLvl4Gk:APA91bGpDom9GS7nsNluv0w_RA5cMfmbG0UNGLK6izua83ubssu1sFcnLGXuBYTej8P-RizQq69ILfrw6wInQ6jlfT0ag2THoaiVNdumduRLVeTG5y4TrXWVQov7oiMNFTXyjjSqUxOk', // The unique identifier for the recipient. For example, an address could be a device token, email address, or mobile phone number.
      attributes: {
          // Custom attributes that your app reports to Amazon Pinpoint. You can use these attributes as selection criteria when you create a segment.
          hobbies: ['coding'],
      },
      channelType: 'GCM', // The channel type. Valid values: APNS, GCM
      demographic: {
          appVersion: '1.0', // The version of the application associated with the endpoint.
      },
      location: {
          city: 'Kelowna', // The city where the endpoint is located.
      },
      // metrics: {
      //     // Custom metrics that your app reports to Amazon Pinpoint.
      // },
      /** Indicates whether a user has opted out of receiving messages with one of the following values:
          * ALL - User has opted out of all messages.
          * NONE - User has not opted out and receives all messages.
          */
      optOut: 'NONE',
      // Customized userId
      userId: '2',
      // User attributes
      userAttributes: {
          interests: ['coding']
      }
    })

    console.log("component did mount");
    PushNotification.onNotification((notification) => {
      console.log('in app notification', notification);
      notification.finish(PushNotificationIOS.FetchResult.NoData);
    });

    PushNotification.onRegister((token) => {
      console.log('in app registration token', token);
    });
  }

  handleAnalyticsClick() {
    console.log("analytics click recorded");
    Analytics.record({
      name: "Button Clicked",
      attributes: { username: "jasonAndroid" }
    }).then( evt => {
          const url = 'https://console.aws.amazon.com/pinpoint/home/?region=us-east-1#/apps/'+config.aws_mobile_analytics_app_id+'/analytics/events';
          let result = (
            <View>
              <Text>Event Submitted.</Text>
              <Text>Events sent: {++this.state.eventsSent}</Text>
              <Text style={styles.link} onPress={() => Linking.openURL(url)}>
                View Events on the Amazon Pinpoint Console
              </Text>
            </View>
          );
          this.setState({
              'resultHtml': result
          });
      });
  };

  render() {
    return (
      <View style={styles.container}>
        <Text>Welcome to your React Native App with Amplify!</Text>
        <Button title="Generate Analytics Event" onPress={this.handleAnalyticsClick} />
        {this.state.resultHtml}
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
  link: {
    color: 'blue'
  }
});

export default withAuthenticator(App, { includeGreetings: true });

I've borrowed a colleagues phone, hoping it was something device specific. But it made no difference.

bernhardt1 commented 5 years ago

@goodryanboy perhaps it is my gradle build files? I had to make some adjustments to get my android project to build properly. I set all my firebase and play-services to versions < 14 to get a successful build.

android/build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
  repositories {
    google()
    jcenter()
  }
  dependencies {
    classpath 'com.android.tools.build:gradle:3.1.4'
    classpath 'com.google.gms:google-services:3.2.0'
    classpath 'de.undercouch:gradle-download-task:2.0.0'
  }
}

allprojects {
  repositories {
    // For non-detach
    google()

    maven {
      url "$rootDir/maven"
    }
    maven {
        // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
        url "$rootDir/../node_modules/react-native/android"
    }
    maven {
        url "https://maven.google.com"
    }
    // For old expoviews to work
    maven {
      url "$rootDir/versioned-abis/expoview-abi25_0_0/maven"
    }
    maven {
      url "$rootDir/versioned-abis/expoview-abi26_0_0/maven"
    }
    maven {
      url "$rootDir/versioned-abis/expoview-abi27_0_0/maven"
    }
    maven {
      url "$rootDir/versioned-abis/expoview-abi28_0_0/maven"
    }
    maven {
      url "$rootDir/versioned-abis/expoview-abi29_0_0/maven"
    }
    maven {
      url "$rootDir/versioned-abis/expoview-abi30_0_0/maven"
    }
    maven {
      url "$rootDir/versioned-abis/expoview-abi31_0_0/maven"
    }
    // For detach
    maven {
      url "$rootDir/../node_modules/expokit/maven"
    }
    maven {
      // We use a modified build of com.android.support.test:runner:1.0.1. Explanation in maven-test/README
      url "$rootDir/maven-test"
    }
    jcenter()
    maven {
      // Local Maven repo containing AARs with JSC built for Android
      url "$rootDir/../node_modules/jsc-android/dist"
    }
    flatDir {
      dirs 'libs'
      // dirs project(':expoview').file('libs')
    }
    maven { url "https://jitpack.io" }

    // Want this last so that we never end up with a stale cache
    mavenLocal()
  }
}

task clean(type: Delete) {
  delete rootProject.buildDir
}

android/app/build.gradle

buildscript {
  repositories {
    google()
    maven { url 'https://maven.fabric.io/public' }
  }

  dependencies {
    classpath 'io.fabric.tools:gradle:1.+'
  }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
  maven { url 'https://maven.fabric.io/public' }
}

android {
  compileSdkVersion 27
  buildToolsVersion '27.0.3'

  defaultConfig {
    applicationId 'com.levity'
    targetSdkVersion 26
    versionCode 1
    versionName '1.0.0'
    ndk {
      abiFilters 'armeabi-v7a', 'x86'
    }
    multiDexEnabled true
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    // Deprecated. Used by net.openid:appauth
    manifestPlaceholders = [
      'appAuthRedirectScheme': 'host.exp.exponent'
    ]
  }
  dexOptions {
    javaMaxHeapSize System.getenv("DISABLE_DEX_MAX_HEAP") ? null : "8g"
  }

  flavorDimensions 'minSdk', 'remoteKernel'
  productFlavors {
    devKernel {
      dimension 'remoteKernel'
    }
    prodKernel {
      dimension 'remoteKernel'
    }
    devMinSdk {
      dimension 'minSdk'
      // dev utilizes minSDKVersion = 21 to allow the Android gradle plugin
      // to pre-dex each module and produce an APK that can be tested on
      // Android Lollipop without time consuming dex merging processes.
      minSdkVersion 21
    }
    prodMinSdk {
      dimension 'minSdk'
      minSdkVersion 21
    }
  }
  buildTypes {
    debug {
      debuggable true
      ext.enableCrashlytics = false
    }
    release {
      minifyEnabled true
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
      zipAlignEnabled true
    }
  }
  signingConfigs {
    debug {
      storeFile file('../debug.keystore')
    }
  }
  lintOptions {
    abortOnError false
  }
  packagingOptions {
    pickFirst "**"
  }
  configurations.all {
    resolutionStrategy.force 'com.android.support:design:27.1.1'
  }
}

configurations.all {
  resolutionStrategy {
    force 'org.webkit:android-jsc:r224109'
  }
}

apply from: 'expo.gradle'

dependencies {
    compile project(':@aws-amplify_pushnotification')
  implementation fileTree(dir: 'libs', include: ['*.jar'])

  implementation 'com.android.support:multidex:1.0.1'

  // Our dependencies
  implementation ('com.google.firebase:firebase-core:12.0.1')
  implementation ('com.google.firebase:firebase-messaging:12.0.1')

  // Our dependencies from ExpoView
  // DON'T ADD ANYTHING HERE THAT ISN'T IN EXPOVIEW. ONLY COPY THINGS FROM EXPOVIEW TO HERE.
  implementation 'com.android.support:appcompat-v7:27.1.1'
  implementation 'com.facebook.android:facebook-android-sdk:4.37.0'
  implementation('com.facebook.android:audience-network-sdk:4.99.0') {
    exclude module: 'play-services-ads'
  }
  compileOnly 'org.glassfish:javax.annotation:3.1.1'
  implementation 'com.jakewharton:butterknife:8.4.0'
  implementation 'de.greenrobot:eventbus:2.4.0'
  implementation 'com.amplitude:android-sdk:2.9.2' // Be careful when upgrading! Upgrading might break experience scoping. Check with Jesse. See Analytics.resetAmplitudeDatabaseHelper
  implementation 'com.squareup.picasso:picasso:2.5.2'
  implementation 'com.google.android.gms:play-services-gcm:12.0.1'
  implementation 'com.google.android.gms:play-services-analytics:12.0.1'
  implementation 'com.google.android.gms:play-services-maps:12.0.1'
  implementation 'com.google.android.gms:play-services-auth:12.0.1'
  implementation 'com.google.android.gms:play-services-location:12.0.1'
  implementation 'com.google.android.gms:play-services-ads:12.0.1'
  annotationProcessor 'com.raizlabs.android:DBFlow-Compiler:2.2.1'
  implementation "com.raizlabs.android:DBFlow-Core:2.2.1"
  implementation "com.raizlabs.android:DBFlow:2.2.1"
  implementation "com.madgag.spongycastle:core:1.53.0.0"
  implementation "com.madgag.spongycastle:prov:1.53.0.0"
  debugImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta1'
  // debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.4-beta1'
  releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta1'
  implementation 'com.facebook.device.yearclass:yearclass:1.0.1'
  implementation 'commons-io:commons-io:1.3.2'
  implementation 'me.leolin:ShortcutBadger:1.1.4@aar'
  implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
  implementation 'com.theartofdev.edmodo:android-image-cropper:2.4.7'
  implementation 'com.yqritc:android-scalablevideoview:1.0.1'
  implementation 'commons-codec:commons-codec:1.10'
  implementation 'com.segment.analytics.android:analytics:4.3.0'
  implementation 'com.google.zxing:core:3.2.1'
  implementation 'net.openid:appauth:0.4.1'
  implementation('com.airbnb.android:lottie:2.5.5')  {
      exclude group: 'com.android.support', module: 'appcompat-v7'
  }
  implementation 'io.branch.sdk.android:library:2.17.1'
  implementation('io.nlopez.smartlocation:library:3.2.11') {
    transitive = false
  }
  implementation 'com.android.support:exifinterface:27.1.1'
  implementation 'com.squareup.okio:okio:1.9.0'
  implementation 'com.facebook.soloader:soloader:0.5.1'

  implementation 'com.google.android.exoplayer:exoplayer:2.6.1'
  implementation 'expolib_v1.com.google.android.exoplayer:expolib_v1-extension-okhttp:2.6.1@aar'

  // expo-file-system
  implementation 'com.squareup.okhttp3:okhttp:3.10.0'
  implementation 'com.squareup.okhttp3:okhttp-urlconnection:3.10.0'

  // Testing
  androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
  // We use a modified build of com.android.support.test:runner:1.0.1. Explanation in maven-test/README
  androidTestImplementation 'com.android.support.test:runner:1.0.1'
  androidTestImplementation 'com.android.support:support-annotations:27.1.1'
  androidTestImplementation 'com.google.code.findbugs:jsr305:3.0.0'
  androidTestImplementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'
  androidTestImplementation 'com.azimolabs.conditionwatcher:conditionwatcher:0.2'

  testImplementation 'junit:junit:4.12'
  testImplementation 'org.mockito:mockito-core:1.10.19'
  testImplementation 'org.robolectric:robolectric:3.8'
  testImplementation 'com.android.support.test:runner:1.0.2-alpha1'
  testImplementation 'com.android.support.test:rules:1.0.2-alpha1'

  implementation('host.exp.exponent:expoview:31.0.0@aar') {
    transitive = true
    exclude group: 'com.squareup.okhttp3', module: 'okhttp'
    exclude group: 'com.squareup.okhttp3', module: 'okhttp-urlconnection'
  }
}

// This has to be down here for some reason
apply plugin: 'com.google.gms.google-services'

As you might remember, I also adjusted the pushnotification build.gradle to have com.firebase:firebase-jobdispatcher-with-gcm-dep:0.6.0 node_modules/@aws-amplify/pushnotification/android/build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
        classpath 'com.google.gms:google-services:3.1.1'
    }
}

allprojects {
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com'
        }
        maven {
            url "https://jitpack.io"
        }
    }
}

apply plugin: "com.android.library"

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.3"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
}

dependencies {
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:+"  // From node_modules

    compile 'com.google.firebase:firebase-messaging:12.0.1'
    compile 'com.google.firebase:firebase-core:12.0.1'
    compile 'com.firebase:firebase-jobdispatcher-with-gcm-dep:0.6.0'

    compile('com.amazonaws:aws-android-sdk-auth-core:2.6.+@aar') {
        transitive = false;
    }
    compile('com.amazonaws:aws-android-sdk-mobile-client:2.6.+@aar') {
        transitive = false;
    }
}
powerful23 commented 5 years ago

@bernhardt1 I am not sure if it's the cause of the issue but you don't need to put

    if (Platform.OS === "ios") {
      PushNotification.initializeIOS();
    } else {
      console.log("initializing android");
      PushNotification.initializeAndroid();
    }

in your client code. The PushNotification module would do it when configure() is called.

bernhardt1 commented 5 years ago

Unfortunately, it fails with or without initializing. I've re-written my app.js to look like this:

import React from 'react';
import { StyleSheet, Text, View, PushNotificationIOS, Platform, Alert } from 'react-native';

import { withAuthenticator } from 'aws-amplify-react-native';

// import Auth from '@aws-amplify/auth';
import Analytics from '@aws-amplify/analytics';
import PushNotification from '@aws-amplify/pushnotification';
import Amplify from 'aws-amplify';

import config from './aws-exports';
import AppIndex from './app/index';

// Auth.configure(config);
// Analytics.configure(config);
// PushNotification.configure(config);
Amplify.configure(config);
Amplify.Logger.LOG_LEVEL = 'DEBUG';

let deviceToken = '';

function setUser() {
  console.log('user device token:', deviceToken);
  Analytics.updateEndpoint({
    Address: deviceToken,
    UserId: deviceToken,
    OptOut: 'NONE'
  });
}

// get the notification data
PushNotification.onNotification((notification) => {
  console.log('push notification found');
  // Note that the notification object structure is different from Android and IOS
  if (Platform.OS === 'android') {
    Alert.alert(
      notification.title,
      notification.body,
      [
        { text: 'OK', onPress: () => console.log('OK Pressed') },
      ],
      { cancelable: false }
    );
  }

  if (Platform.OS === 'ios') {
    Alert.alert(
      'notification',
      'notification description',
      [
        { text: 'OK', onPress: () => console.log('OK Pressed') },
      ],
      { cancelable: false }
    );
    notification.finish(PushNotificationIOS.FetchResult.NoData);
  }
});

// get the registration token
PushNotification.onRegister((token) => {
  deviceToken = token;
});

class App extends React.Component {
  componentDidMount() {
    if (Platform.OS === 'ios') {
      PushNotificationIOS.requestPermissions();

      PushNotification.onRegister((token) => {
        deviceToken = token;
        console.log('ios deviceToken Set', token);
        setUser();
      });
    }
  }

  render() {
    if (Platform.OS === 'android') {
      console.log('setuser in render');
      setUser();
    }
    return (
      <View style={styles.container}>
        <Text>Welcome to your React Native App with Amplify!</Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
  link: {
    color: 'blue'
  }
});

export default withAuthenticator(App, { includeGreetings: true });

iOS continues to work and android is still getting nothing.

The steps to create my problem are as follows:

@powerful23 Have you see any issues related to ejecting to expokit? Or perhaps the changes to the build.gradle file is responsible?

Luckygirlllll commented 5 years ago

Is there any updates regarding this issue? I

stale[bot] commented 5 years ago

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

stale[bot] commented 5 years ago

This issue has been automatically closed because of inactivity. Please open a new issue if are still encountering problems.

my-name-is-nheo commented 3 years ago

I'm having issues with this. I successfully getting the endpoint Id by const endpointId = Analytics.getPluggable('AWSPinpoint')._config.endpointId; But when I go to the pinpoint console, I'm not seeing any activity whatsoever. Even sending a test message through the endpoint ID is leading to an error saying endpoint does not exist. Am I missing something here? Screen Shot 2021-02-11 at 2 09 51 PM

Razzendah commented 3 years ago

my-name-is-nheo im have the same problem, did you solve it?

github-actions[bot] commented 2 years ago

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.