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

Commit

Permalink
fix: match android native method name same as IOS
Browse files Browse the repository at this point in the history
  • Loading branch information
vijaygojiya authored and gtokman committed Feb 16, 2024
1 parent 34999c1 commit 78d1235
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 37 deletions.
13 changes: 3 additions & 10 deletions android/src/main/java/com/candlefinance/push/PushModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ class PushModule(reactContext: ReactApplicationContext) :
return NAME
}

// Example method
// See https://reactnative.dev/docs/native-modules-android
@ReactMethod
fun multiply(a: Double, b: Double, promise: Promise) {
promise.resolve(a * b)
}



Expand All @@ -50,8 +44,8 @@ class PushModule(reactContext: ReactApplicationContext) :

val listener = PermissionListener { requestCode: Int, _: Array<String>, grantResults: IntArray ->
if (requestCode == currentRequestCode) {
val permissionStatus = if (grantResults.isNotEmpty()) grantResults[0] else PackageManager.PERMISSION_DENIED
promise.resolve(permissionStatus== PackageManager.PERMISSION_GRANTED)
val isPermissionGranted = grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED
promise.resolve(isPermissionGranted)
return@PermissionListener true
}
return@PermissionListener false
Expand All @@ -70,15 +64,14 @@ class PushModule(reactContext: ReactApplicationContext) :
}

@ReactMethod
fun getToken(promise: Promise) {
fun registerForToken(promise: Promise) {
FirebaseMessaging.getInstance().token.addOnCompleteListener(OnCompleteListener { task ->
if (!task.isSuccessful) {
Log.w("getTokenError", "Fetching FCM registration token failed", task.exception)
promise.reject(task.exception)
return@OnCompleteListener
}

// Get new FCM registration token
val token = task.result
promise.resolve(token)
})
Expand Down
13 changes: 0 additions & 13 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,6 @@ export default function App() {
title="Register for Token"
onPress={() => push.registerForToken()}
/>
<Button
title="Get FCM Token"
onPress={() =>
push
.getToken()
.then((token) => {
console.log('Token :', token);
})
.catch((e) => {
console.log('Error while fetching deivce FCM token', e);
})
}
/>
</View>
);
}
Expand Down
15 changes: 1 addition & 14 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,12 @@ class Push {
}

public async requestPermissions(): Promise<boolean> {
// if (Platform.OS === 'ios') {
const result = await this.module.requestPermissions();
return result;
// }
// return false;
}

public async registerForToken(): Promise<boolean> {
if (Platform.OS === 'ios') {
return this.module.registerForToken();
}
return false;
}

public async getToken(): Promise<boolean> {
if (Platform.OS === 'android') {
return this.module.getToken();
}
return false;
return this.module.registerForToken();
}

public async isRegisteredForRemoteNotifications(): Promise<boolean> {
Expand Down

0 comments on commit 78d1235

Please sign in to comment.