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

Commit

Permalink
fix: add new auth method and update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
gtokman committed Feb 17, 2024
1 parent d48ef91 commit a28ff16
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 26 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,23 @@ Andriod support is coming soon. Checkout [#1](https://github.com/candlefinance/p
2. If your AppDelegate is in Objective-C (`.mm|.m|.h`), create a new `AppDelegate.swift` file and bridging header then delete the Objective-C AppDelegate and main.m file. Finally copy the contents of the example app's [AppDelegate.swift](./example/ios/AppDelegate.swift) and [bridge header](./example/ios/PushExample-Bridging-Header.h) to your project.
3. Make sure you're on `iOS 15` or later.

### Android

- [x] Request permissions
- [x] Register for FCM token
- [ ] Remote push notifications
- [ ] Foreground
- [ ] Background
- [ ] Opened by tapping on the notification
- [ ] Local push notifications

#### Setup

1. Add permissions in [AndroidManifest.xml](./example/android/app/src/main/AndroidManifest.xml)
2. Add `google-services.json` in `android/app` directory from Firebase console.

## API

<br>
The following code is used to handle push notifications on the React Native side:

Expand Down
17 changes: 16 additions & 1 deletion android/src/main/java/com/candlefinance/push/PushModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,22 @@ class PushModule(reactContext: ReactApplicationContext) :
}



@ReactMethod
fun getAuthorizationStatus(promise: Promise) {
val context = reactApplicationContext.baseContext

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
if (ContextCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS) ==
PackageManager.PERMISSION_GRANTED
) {
promise.resolve(2) // authorized
} else {
promise.resolve(1) // denied
}
} else {
promise.resolve(2) // authorized
}
}

@ReactMethod
fun requestPermissions(promise: Promise) {
Expand Down
14 changes: 7 additions & 7 deletions example/android/app/google-services.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{
"project_info": {
"project_number": "474493224162",
"project_id": "candlefinance-f9ffc",
"storage_bucket": "candlefinance-f9ffc.appspot.com"
"project_number": "123",
"project_id": "123",
"storage_bucket": "exampe-fffc.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:474493224162:android:11939c10bf7baedf0b4abb",
"mobilesdk_app_id": "Example",
"android_client_info": {
"package_name": "com.trycandle.candle"
"package_name": "com.pushexample"
}
},
"oauth_client": [],
"api_key": [
{
"current_key": "AIzaSyAdqU_q_VE4tgIURcncbH80Q-NUuRXlEfk"
"current_key": ""
}
],
"services": {
Expand All @@ -26,4 +26,4 @@
}
],
"configuration_version": "1"
}
}
32 changes: 14 additions & 18 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,26 +77,22 @@ class Push {
}
}

// https://developer.apple.com/documentation/usernotifications/unauthorizationstatus?ref=createwithswift.com
public async getAuthorizationStatus(): Promise<AuthorizationStatus> {
if (Platform.OS === 'ios') {
const value: number = await this.module.getAuthorizationStatus();
switch (value) {
case 0:
return 'notDetermined';
case 1:
return 'denied';
case 2:
return 'authorized';
case 3:
return 'provisional';
case 4:
return 'ephemeral';
default:
return 'notDetermined';
}
const value: number = await this.module.getAuthorizationStatus();
switch (value) {
case 0:
return 'notDetermined';
case 1:
return 'denied';
case 2:
return 'authorized';
case 3:
return 'provisional';
case 4:
return 'ephemeral';
default:
return 'notDetermined';
}
return 'denied';
}

public addListener<T extends keyof NotificationCallbacks>(
Expand Down

0 comments on commit a28ff16

Please sign in to comment.