Ionic Firebasex don't work in background (iOS) - ios

I'm working with Ionic3 and using FirebaseX Cordova Plugin (because firebase plugin it's not working at all) and when the App is foreground (opened) the message get in the App (not as a notification) perfect, but when in background (using another app) the notification don't show... when I open back the App, the message get in the App (not as a notification)...
I'm using the Author example EXACTLY (only changed the bundle id so I could register as a Firebase Project)
I use a paid developer account, I have defined a APN, uploaded to firebase etc.
Activate the Remote Notification in Capabilities (both on Push and Background)
But still...
Something strange is that when the App opens, it says in the log:
2019-10-25 11:20:50.152424-0300 FirebaseX Ionic 3 Example[560:180512] FCM direct channel = true
and when the App goes background, the login says:
2019-10-25 11:20:50.152424-0300 FirebaseX Ionic 3 Example[560:180512] FCM direct channel = false
And when I open the App again it goes back to true again, and receive the notification!
I know that FCM is Firebase Cloud Messagin, so... but I don't know why it turns false
Please, help! Thanks!

I found the solution! Maybe it helps someone... Now with the FirebaseX Cordova Plugin You need to ask for permission explicitly (with the old firebase cordova plugin, was automaticly asked...)
insert this code:
this.firebasePlugin.grantPermission(function(hasPermission){
console.log("Permission was " + (hasPermission ? "granted" : "denied"));
});
and that's it (if the user say 'yes'!)

In firebasex cordova plugin you have to ask for permission like this.
You can only call grantPermission() if hasPermission() returns false:
window.FirebasePlugin.hasPermission(function(hasPermission){
if(!hasPermission){
window.FirebasePlugin.grantPermission(function(permissionGranted){
if(permissionGranted){
console.log("Permission granted");
}else{
console.warn("Permission denied");
}
});
}else{
console.log("Permission already granted");
}
});

Related

Authenticate with Firebase on IOS using a Phone Number

I am working on a Xamarin Forms application and using an iPhone simulator to test the Firebase authentication using phone number. I have checked all project setup needed on to Console and inside the app but I am getting the
Method name: DidReceiveRemoteNotification
Information: {
"com.google.firebase.auth" = {
warning = "This fake notification should be forwarded to Firebase Auth.";
};
}
all the time. I know that because I am using a simulator I will have to go through recaptcha process for this that has also been done (Added Url Scheme for that). Any help or suggestion that can help me to get this problem sorted will be a great help.

LinkedIn sdk iOS error if already logged in to LinkedIn App

I'm using the iOS LinkedIn SDK to log into my App and retrieve basic profiles.
All works perfectly fine the first time I login, until either I log out, or I close my App.
On attempting to log back into my App with LinkedIn: the usual redirect to the LinkedIn app takes place, but the permissions screen for my app doesn't pop up, it just redirects straight back to my app with the following error:
Error Domain=LISDKAuthError Code=5 "(null)" UserInfo={errorDescription=The operation couldn’t be completed. Software caused connection abort, originalDomain=LISDKServerError, errorInfo=PARSING_ERROR}
I can only successfully log back in again if I first close the LinkedIn App, before reopening mine.
Does anyone have an idea of what's going on please?
-This doesn't occur on all of my test devices!
-On the device that it does occur on, I also receive the same error in that scenario when running the sample App provided with the LinkedIn SDK.
-The LinkedIn App is up to date.
-The App id, bundle ids etc etc are all set, hence login success half of the time!
-I've tried calling [LISDKSessionManager clearSession] in numerous locations.
Cheeky framework fix alert.
Uncomment out the lines in LISDKSession.h
This allows the correct use of [LISDKSessionManager hasValidSession]
Which is an improvement on what we were working with.
Not yet tested with iOS12...
I had a similar problem. It was mainly reproduced only on iOS 12. The problem is that when you already have a LinkedIn application running, you will not be able to log in through their SDK in your application. On iOS 11, the second time you try to log in after this error, the authorization worked fine.
I solved this issue by simply showing the user an alert with a message about what he needs to do to authorize.
Here you can check an example of my implementation in Swift 4:
LISDKSessionManager.createSession(withAuth: ["r_basicprofile"],
state: nil,
showGoToAppStoreDialog: true,
successBlock: { _ in
// Your actions in case of successful authorization
}, errorBlock: { error in
guard let nsError = error as NSError? else {
return
}
if #available(iOS 12.0, *),
nsError.code == LISDKErrorCode.SERVER_ERROR.rawValue {
// Show alert to user with text - "Please, shut down the LinkedIn app and try login again"
} else if nsError.code != LISDKErrorCode.USER_CANCELLED.rawValue {
// Handling when user tap on Cancel button in LinkedIn SDK
}
})
I've been battling for a fix for this with LinkedIn for months.
There 'solution' is to kill off the SDK.
Taken from their 'Important updates to the LinkedIn Developers program and APIs' email December 2018:
"Authentication, SDKs, and Plugins: We are also deprecating several obsolete or seldomly-used products and technologies."
"SDKs: Our JavaScript and Mobile Software Development Kits (SDKs) will stop working. Developers will need to migrate to using OAuth 2.0 directly from their apps."
Uncomment this two lines of code in LISDKSession.h
- (LISDKAccessToken *)getAccessToken;
- (void)setAccessToken:(LISDKAccessToken *)accessToken;

ionic framework 2.0 push notifications on event not found

I am really struggling to add push notification support to my Ionic application. My current issue is related to the documentation, which states that I need to add a cordova push plugin (which I have) and then to add the following event handler:
this.push.on('notification', function (data) {
// do something with the push data
// then call finish to let the OS know we are done
push.finish(function () {
console.log("processing of push data is finished");
}, function () {
console.log("something went wrong with push.finish for ID = " + data.additionalData.notId)
}, data.additionalData.notId);
});
However, I am getting an on property not found the error. How do I fix this issue?
That's correct. The browser outputs that this.push.on is not a function. Probably has to do with the browser not supporting Push and it's native capabilities.
However, using it in your mobile applicationw ill work just fine. If you want to make the error go away because it is confusing you could check on which OS the user currently is or check if he has cordova.
This can be done by wrapping your push.on in a if(this.platform.is('cordova')){} or if(platform.is('cordova')) (not sure about the this.) Source: How to detect if I am in browser (local development) in Ionic 2

OneSignal iOS SDK send notification fail Code 400

What I have done:
I have created a simple iOS native App which has nothing but OneSignal initializaion codes. I installed my App on my 2 devices, device A and device B. Both devices are subscribed to my OneSignal App Console. When I send a notification from OneSignal Web Console, the 2 devices can both recive the notification.
What I want to do:
When I click on a button on device A, device A will send a notification to device B.
What is the problem:
I followed the OneSignal iOS SDK document and created the following function
https://documentation.onesignal.com/docs/ios-native-sdk#section-sending-notifications
func onButtonClick() {
OneSignal.postNotification(
[
"contents": ["en": "Test Message"],
"include_player_ids": ["c00bb8a6-79da-419b-9999-e919831a5223"] // id of device B
],
onSuccess: {(result) in print("success") },
onFailure: {(error) in print("error : \(error)") }
)
}
however, when I clicked the button, an error shows up in the xCode debug console:
2017-01-20 11:15:52.702852 my.bundle.id[2263:1201122] ERROR: Create notification failed
error : Optional(Error Domain=OneSignalError Code=400 "(null)" UserInfo={returned={
errors = (
"Please include a case-sensitive header of Authorization: Basic <YOUR-REST-API-KEY-HERE> with a valid REST API key."
);
reference = (
"https://documentation.onesignal.com/docs/accounts-and-keys#section-keys-ids"
);
}})
I was confused, because according to the OneSignal Reference document, send notification with "include_player_ids" Does not require API Auth Key.
https://documentation.onesignal.com/reference#create-notification
And it also says: NEVER use your 'REST API key' in client code, it is intended for use on your system or server only.
So what does this error mean? And what should I do?
I even copied and run this "work without any problems" code from this discussion, but the same Authorization error still shows up. What am I doing wrong?
The Answer
Just upgrade the SDK and the problem will be gone.
This was a bug in OneSignal-iOS-SDK 2.3.1, this bug was fixed in 2.3.2.
Please see their Github Release Notes.
How to avoid this kind of problems
Always run pod repo update before pod install to ensure that the pod install the latest version of the frameworks.
Thanks Kevin, Jason and Josh from One Signal Conversations to help me solve this problem.

Should FB.ActivateApp be manually called on iOS

We are using the latest available version of the Facebook SDK for Unity (v7.2.2)
One of the available APIs is ActivateApp (FB.ActivateApp).
Should this method be called, specifically on iOS ?
Digging a bit into what's under the hood (the SDK is open source), I see that on iOS (in the file FBUnityInterface.mm), there's the following code:
- (void)didBecomeActive:(NSNotification *)notification
{
[FBSDKAppEvents activateApp];
}
It looks like ActivateApp is being called automatically (whether i manually call it or not).
Should we call FB.ActivateApp when our app starts / resumes? won't this cause duplicate app activation reports ?
Answering my own question:
On iOS, ActivateApp seems to be called automatically in iOS native code.
Invoking the FB.ActivateApp method does nothing (see this code from IOSFacebook.cs):
public override void ActivateApp(string appId)
{
IOSFacebook.IOSFBSettingsActivateApp(appId);
}
The called method is simply empty:
private static void IOSFBSettingsActivateApp(string appId)
{
}
So, this seems to be taken care of automatically on iOS.
Just to chime in here. We currently had a bug where when using UnityIAP, if a user bought a consumable IAP and quit the app before marking it Complete, they wouldn't get notified of the purchase on app restart.
In the end it came down to Facebook's automatic logging of IAP events in iOS (SDK >= 3.22). I think because it was adding a listener to the transaction queue before Unity.
I mention this because to turn on FB's auto logging of IAP, you need to set it in:
developers.facebook.com > App > Settings > Basic > iOS > iOS Only: Log In-App Purchase Events Automatically (Recommended)
Then call ActivateApp(). However, this is done automatically for you on iOS, so that only leaves the setting on the website or changing the code.
Long story short, if you're using Unity IAP and you're not getting purchase callbacks for incomplete purchases on iOS startup, it's either because of FB or another plugin adding a transaction queue listener (another user reported the possibility of AdMob). For us it was FB.
http://forum.unity3d.com/threads/iap-restorepurchase-on-ios-not-return-processpurchase-callback.392000/

Resources