I integrated react-native-push-notification with ios and android following the documentation, also some tutorials on youtube, but I have a problem, I'm not receiving any notification, even local notification, on the iOS device, but on Android, it's working well. I don't know if I need to show you the code, because is the same as in the documentation.
By the way, I'm using firebase for cloud messaging and I configured it with my p8 key.
I had the similar issue even though every related settings were turned on. Was frustrating - i used "hi security " from Google Play store which manages the notifications. After "notification" was set to ON, I found all of the badges are showing up - missed call and unread messages on both home screen and app.
I also tried with react-native-firebase but it does not work.No push notification is received . Later I Implemented push notification using react-native-fcm and it worked. You can check the link https://github.com/evollu/react-native-fcm
You are not receiving notification probably because firebase is not integrated properly in your application. The steps to integrate properly are given below:
react-native-firebase library did not work for me .Integrating firebase to react native application using react-native-fcm succeded in receiving push notifications.
1.Install react-native-fcm:
npm install react-native-fcm --save
From firebase console,
for Android: download google-services.json file and place it in android/app directory.
for iOS: download GoogleService-Info.plist file and place it in /ios/your-project-name directory (next to your Info.plist)
3.Configure the project using :
cd ios && pod init
4.Edit the newly created Podfile:
pod install
5.Edit AppDelegate.h:
#import UserNotifications;
#interface AppDelegate:UIResponder<UIApplicationDelegate,UNUserNotificationCenterDelegate>
#interface AppDelegate : UIResponder <UIApplicationDelegate>
6.Edit AppDelegate.m:
#import "RNFIRMessaging.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[FIRApp configure];
[[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];
return YES;
}
-(void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^) .
(UNNotificationPresentationOptions))completionHandler
{
[RNFIRMessaging willPresentNotification:notification
withCompletionHandler:completionHandler];
}
#if defined(__IPHONE_11_0)
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)(void))completionHandler
{
[RNFIRMessaging didReceiveNotificationResponse:response
withCompletionHandler:completionHandler];
}
#else
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void(^)())completionHandler
{
[RNFIRMessaging didReceiveNotificationResponse:response
withCompletionHandler:completionHandler];
}
#endif
//You can skip this method if you don't want to use local notification
-(void)application:(UIApplication *)application
didReceiveLocalNotification:(UILocalNotification *)notification {
[RNFIRMessaging didReceiveLocalNotification:notification];
}
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo
fetchCompletionHandler:(nonnull void (^) .
(UIBackgroundFetchResult))completionHandler{
[RNFIRMessaging didReceiveRemoteNotification:userInfo
fetchCompletionHandler:completionHandler];
}
7.Add the path of header files into XCode:
Open XCode.
Press CMD+1 or click the XCode project.
Go to Build Settings, selecting All and Combined.
Search Header Search Path in the searchg tab.
Make sure there is a line of $(SRCROOT)/../node_modules/react-native-fcm/ios. If no, just add it.
8.Add GoogleService-Info.plist:
Make sure the file is not just moved into the folder. You need to Right Click the project folder in XCode and Add File to . Select Copy if needed in the Options page while selecting the file.
9.Shared Library Settings:
Make sure you see Pods.xcodeproj under Library folder if you are using Pod install method.
Make sure you see RNFIRMessaging.xcodeproj under Library folder.
If you don't see any of these files, please add them by Right Click the Library folder and Add File to to add them back. Pods.xcodeproj should be under ios/Pods/, and RNFIRMessaging.xcodeproj should be under node_modules/react-native-fcm/ios.
Make sure you see libRNFIRMessaging.a under Link Binary With Libraries under Build Phases tab. If no, drag the file under RNFIRMessaging.xcodeproj under Library folder into there.
10.Add Capabilities
Select your project Capabilities and enable:
Push Notifications
Background Modes > Remote notifications.
FirebaseAppDelegateProxyEnabled
This instruction assumes that you have FirebaseAppDelegateProxyEnabled=YES (default) so that Firebase will hook on push notification registration events. If you turn this flag off, you will be on your own to manage APNS tokens and link with Firebase token.
Related
In my Ionic 5 app, I am using the capacitor-community/sqlite plugin. I am successfully able to create and use an encrypted db with this plugin. To use encryption a secret is required and the following is maintained in the official documentation as of today.
Defining your own secret and newsecret keys (encryption only)
in IOS, go to the Pod/Development Pods/capacitor-sqlite/GlobalSQLite.swift file
in Android, go to capacitor-sqlite/java/com.jeep.plugin.capacitor/cdssUtils/GlobalSQLite.java
and update the default values before building your app.
in Electron, go to YOUR_APP/electron/plugins/plugin.js-xxxx.js and search for class GlobalSQLite and modify the this.secretand
this.newsecret parameters.
I have searched for files GlobalSQLite.swift and GlobalSQLite.java in IOS and android respectively but there are no such files present. Also, the file paths are not available. I am not sure how to get these files to set my secret in the app. Please help.
You should look for the GlobalSQLite.java in node_modules\#capacitor-community\sqlite\android\src\main\java\com\getcapacitor\community\database\sqlite\SQLite. After changing the secrets you may need to sync the platforms with ionic cap sync.
The iOS and Electron files you also find there
I want to use this cordova plugin at https://github.com/katzer/cordova-plugin-local-notifications
How to go about integrating this plugin with my existing IBM Worklight project? I have trying various methods to integrate it without any result.
I am getting this error currently from the logcat:
02-24 11:15:03.035: D/CordovaLog(2439): file:///data/data/com.iCareApp/files/www/default/index.html: Line 17 : Uncaught TypeError: Cannot read property 'notification' of undefined
Or is there any other easier alternatives to get this done? Basically i want to be able to schedule local notification on the device at specific times from the data stored in my application
I got this to work by following the below.
Demo project: https://www.dropbox.com/s/58urdluauc8u3l1/AndroidLocalNotifications.zip
Because Worklight does not support Cordova's Plugman to easily "install" Cordova v3 plug-ins, some manual labor is required to get it all set-up properly... blachs.
Note the appName , it is used throughout the process for plug-in declarations. If you use a different name for in your app, you will need to update the values accordingly with yours.
Pay attention to the nativeResources folder, where I've placed the files I edited:
AndroidManifest.xml:
In it I added the required permission, receivers, activities
libs folder:
Contains required .jar file by the plug-in
src folder:
Contains the plug-in's Java classes
In them I've edited the plug-in import declaration
res\xml folder:
Contains config.xml; see at the bottom for the plug-in feature declaration
In index.html:
The plug-in's JavaScript implementation is referenced in the head element
<script src="js/local-notification.js"></script>
In main.js:
function wlCommonInit(){
window.plugin.notification.local.add({ message: 'this is a local notification' });
}
The above will send a local notification immediately after the application's launch.
In the plug-in's homepage you can read more about the possible notification options.
In local-notification.js:
Add at the top:
cordova.define("LocalNotification", function(require, exports, module) {
Add at the bottom:
});
In the generated Android project\assets\www\default\js\worklight\cordova_plugins.js, add:
,
{
"file": "../js/local-notification.js",
"id": "LocalNotification",
"clobbers": [
"plugin.notification.local"
]
}
Note that re-building the Worklight project will overwrite this file, and thus your changes in it will be gone... you'll need to repeat this step after every build.
There is no good way that I could find to preserve changes to this file between Worklight Studio builds.
I have been trying to send sms from my app without user intervention programmatically however there is no success.
I have tried the intent method
var intent = Ti.Android.createIntent(
{
action: Ti.Android.ACTION_SENDTO, data: 'smsto:1234567890'
});
intent.putExtra('sms_body', 'Geolocation:'
+ ' long ' + e.coords.longitude
+ ' lat ' + e.coords.latitude);
Ti.Android.currentActivity.startActivity(intent);
});
This sends the sms as well as the message text properly. but the only problem is it need human intervention. it calls the inbuild sms functionality and we have to press the send sms button I want to automate the process.
I found this link on github Click Here
It says we can automate the process. When I try to install the module titanium shows the module installed correctly, however in the ti app editor it says ti.android.sms module not supported by titanium SDK version 3.1.2 GA .
In the build.properties file which the original developer has provided it shows his paths to sdk 3.0.0 GA. I tried to change the build.properties file and provided the paths for android, titanium and google api with the versions and then install the module but I have no success.
I have plugin org.apache.cordova.core.media-capture installed successfully.
Which I did on my project with
phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture.git
navigator.device.capture.captureVideo function does not respond to the call.
Nothing happens on the phone.
If I put an alert in front of and in back of the call to it, the first alert pops but the second never happens. I would expect a failure to go to the captureError callback function
and pop up a message but still nothing happens.
/**
*
* captures the video
* A button will call this function
* Launch device video recording application,
* allowing user to capture 1 video clip
*/
function onCaptureVideo() {
var options = { limit: 1 };
alert('trying to capture');
// start image capture
navigator.device.capture.captureVideo(captureSuccess, captureError, options);
}
Also the callback functions
/**
* Called when capture operation is finished
* #param mediaFiles
*/
var captureSuccess = function(mediaFiles) {
var i, path, len;
for (i = 0, len = mediaFiles.length; i < len; i += 1) {
path = mediaFiles[i].fullPath;
// do something interesting with the file
}
};
/**
*
* Called if something bad happens.
* #param error
*/
var captureError = function(error) {
navigator.notification.alert('Error code: ' + error.code, null, 'Capture Error');
};
This needs to work so I can capture videos and pictures on android and IOS, and then upload them to the server.
Currently I am testing this on an Android Samsung Galaxy S4
Anyone have any ideas on how to get the video capture working?
The problem was that for whatever reason phonegap 3.0 gets a little glitchy and does not seem to want to add new plugins to the android.json file in the app/plugins folder and then does not include the plugins in the app/platforms/android/assets/www/plugins folder when it builds and then also does not add some of the plugins files to app/platforms/android/src/org/apache/cordova/{plugin folder name} folder. in this case "mediacapture".
I had tried adding plugin files manually to app/platforms/android/assets/www/plugins but without the plugin being properly added to app/plugins/android.json. It just deletes them and does not use them next time you build.
Unless your are an expert, android.json really needs to be done by phonegap.
So what I had to do was, backup my app/platforms/android/src/org/apache/cordova/ folder
And also app/platforms/android/assets/www/plugins folder.
Then I moved my project folder in it's entirety off to another location as a firm backup and pulled my project source down from git hub and rebuilt the entire project like so.. Also I must give credit to Adam Wade Harris, you will find him on here, also with phonegap questions and answers and he gave me part of this script.
Put in your real project and reverse domain here and app name
phonegap create {newAppFolderName} com.somedomain.prefix AppShortName
cd newAppFolderName
phonegap build android
setup git with a fake branch
git init
put in your real project repo here
git remote add origin git#bitbucket.org:someorganization/yourrepo.git
git fetch origin
git checkout -b nothingBranch
git add .
git commit -m "nothing"
Checkout your real branch here
git checkout -b master origin/master
git branch --set-upstream-to=origin/master master
create the platforms folder in your project
mkdir /path/to/newAppFolderName/platforms/
Do this for each plugin you might have like so
phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-device.git
phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information.git
phonegap build android
This may not work for everyone, make sure you keep your original project off somewhere and hope for the best, copy any plugin files that ended up being missing, even with a clean rebuild, phonegap seemed to leave out several folders and I had to put them in place again manually.
I'm facing a problem and would really appreciate your help...
Android SDK: 4.0
Phonegap: 1.8.1
Pusher: 1.12
I have created an Android project using Phonegap that needs to receive server notifications through Pusher.
I'm running it in Eclipse and AVD emulator, but the problem is that every time I try to establish a connection to pusher, I get an Unavailable state from the bind to state_change.
I have tested the connection to Internet in the emulator browser and it works fine. I have also tested that the server is responding and that the Pusher key is the right one by testing my code on Firefox.
This are the steps I have followed:
I have included the WebSocket.java and WebSocketFactory.java files in the src folder.
I have included websocket.js file in my js folder and included a reference in the index.html file.
I have included a reference to http://js.pusher.com/1.12/pusher.js in the index file.
I have included the following line in my Android App.java file: this.appView.addJavascriptInterface(new WebSocketFactory(this), "WebSocketFactory");
This is the code I'm using to connect to Pusher:
// Connect
var pusher = new Pusher(CONFIG.PUSHER.APP_KEY);
pusher.connection.bind('state_change', connectionStateChange);
function connectionStateChange(state) {
alert(state.current);
}
Is there something I'm missing? Any ideas on why the connection is not working or about where to check?
Thanks for your help.
Chadid
For version 2.x of pusher-js and above the library will work within PhoneGap without any additional requirements or setup. Simply include the library and use it - no need for WebSocket.java or WebSocketFactory.java.
For version 1.x this blog post and associated code demonstrates how to get Pusher working on PhoneGap:
http://blog.pusher.com/2012/7/5/pusher-on-phonegap-for-android