Comments (28)
Yes same issues, searched for answers and no luck, hope the solution is provided here:
from nativescript-onesignal.
@elconix I am still looking for a way to implement it. Have you found anything what works? I am on the half way to implement this https://documentation.onesignal.com/docs/ios-sdk-setup as native (if possible). Having trouble adding last piece of puzzle from Step 5 - Add the OneSignal Initialization Code
If anyone knows where and how to add this, it would help a lot. Thc
from nativescript-onesignal.
Hello @markosole all nativescript plugins suffer the same thing, so mark this will be a new plugin?
from nativescript-onesignal.
@elconix
I have some good news for you.
Code below works - I can see phone registering on OneSignal. There is one minor problem, OneSignal shows Other Apns 3000 error which I have to fix. That should not be a problem.
My code:
//app.js
var TnsOneSignal = require('nativescript-onesignal').TnsOneSignal;
if (application.ios) {
const MyDelegate = (function (_super) {
__extends(MyDelegate, _super);
function MyDelegate() {
_super.apply(this, arguments);
}
MyDelegate.prototype.applicationDidFinishLaunchingWithOptions = function (application, launchOptions) {
console.log('Init onesignal started...');
console.log("applicationWillFinishLaunchingWithOptions: " + launchOptions);
try {
console.log('Onesignal pokretanje: ', TnsOneSignal);
console.log('###################################################################################');
TnsOneSignal.initWithLaunchOptions({ kOSSettingsKeyAutoPrompt: true, kOSSettingsKeyInAppLaunchURL: true, kOSSettingsKeyInFocusDisplayOption: 2, kOSSettingsKeyProvidesAppNotificationSettings: true });
TnsOneSignal.setAppId("xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx");
TnsOneSignal.init({
kOSSettingsKeyAutoPrompt: true,
});
} catch (error) {
console.log("Error: ", error)
}
return true;
};
MyDelegate.prototype.applicationDidBecomeActive = function (application) {
console.log("iOS aplikacija je aktivirana: " + application);
};
MyDelegate.ObjCProtocols = [UIApplicationDelegate];
return MyDelegate;
})(UIResponder);
application.ios.delegate = MyDelegate;
}
What I have noticed, OneSignal have changed the way of accepting parameters, therefore TnsOneSignal.initWithLaunchOptionsAppId
can not be used. The AppId and Parameters are now sent separately, as in my example above. Another thing is number of parameters and used in: TnsOneSignal.initWithLaunchOptions({ kOSSettingsKeyAutoPrompt: true, kOSSettingsKeyInAppLaunchURL: true, kOSSettingsKeyInFocusDisplayOption: 2, kOSSettingsKeyProvidesAppNotificationSettings: true });
There are some more added there as iOS 13+ requires that. Check screenshot below. As said before, functions can be added and I will fork to and add those changes once I solve APN problem.
EDIT; for your previous question - if you migrated your project to NS7 (which I believe you had to if want to publish for ios 14) than all plugins must be updated. It took me a week to get it all sorted (the ones I am using).
Let's fix OneSignal first and I will try to help with others if can.
from nativescript-onesignal.
Wow @markosole awsome news, so steps:
1- Add JS code in app.ios.js (I have separate app.js for each platform)
2- Replace with our app id,
3- The screenshot I did not understand very well, what should we do for this?
from nativescript-onesignal.
You are correct, go give it a try :)
-
- correct add code I've pasted above to your app.ios.js. Do not forget to include
const application = require(@nativescript/core).Application;
, that is new way of including it and replaces tns-core-modules/application
- correct add code I've pasted above to your app.ios.js. Do not forget to include
-
- Add your App ID instead xxxxxx-xxxxxx-xxxxxxx-xxxxx
-
- Screen shot is for reference only for those who are looking for more info about OneSignal SDK changes.
I am working on APN 3000 error. You try and let me know how it goes for you.
from nativescript-onesignal.
@markosole I use pure js, so it will be this code you attached right?
from nativescript-onesignal.
Just for your refference:
CONSOLE LOG file: app/app.ios.js:50:0: Init onesignal started...
CONSOLE LOG file: app/app.ios.js:51:0: applicationWillFinishLaunchingWithOptions: null
CONSOLE LOG file: app/app.ios.js:54:0: Onesignal pokretanje: function OneSignal() {
[native code]
}
CONSOLE LOG file: app/app.ios.js:55:0: ###################################################################################
CONSOLE LOG file: app/app.ios.js:63:0: Error: Error: Actual arguments count: "1". Expected: "0". (evaluating 'TnsOneSignal.init({
kOSSettingsKeyAutoPrompt: true,
})')
I suppose it initialize ok.
from nativescript-onesignal.
OK no the next step is to get the person id, for that in my login procedure I added this code:
var onesignal_status=TnsOneSignal.getPermissionSubscriptionState(); formData.append('onesignal_id', onesignal_status.getSubscriptionStatus().getUserId());
Got this in console:
JavaScript error: file: app/screens/login/login-view-model.js:51:0: JS ERROR TypeError: TnsOneSignal.getPermissionSubscriptionState is not a function. (In 'TnsOneSignal.getPermissionSubscriptionState()', 'TnsOneSignal.getPermissionSubscriptionState' is undefined) NativeScript caught signal 11.
Is there a new way to get the person id, or is not yet implemented? O need to update the onesignal-plugin?
from nativescript-onesignal.
Just as a good sign, I do see the Iphone Simulator in the Onesignal dashboard.
from nativescript-onesignal.
Ok @markosole worked to compile well in ios, change my old code to:
if(TnsOneSignal.getDeviceState()) {
console.log('Onesignal personid: ', TnsOneSignal.getDeviceState().userId);
formData.append('onesignal_id', TnsOneSignal.getDeviceState().userId);
}
the only issue now is that this code does not work for android and also the TnsOneSignal.getPermissionSubscriptionState does not work.
from nativescript-onesignal.
Do i need to change something in android? the error in android now is:
System.err: TypeError: TnsOneSignal.getDeviceState is not a function
from nativescript-onesignal.
Just as a good sign, I do see the Iphone Simulator in the Onesignal dashboard.
Yeah but what does it say? "Never Prompted" or all looks okey? - I am getting this "Never Prompted" message and still trying to solve it.
- TypeError: TnsOneSignal.getDeviceState This is for Android, it was not implemented in iOS, at least not the same way. You can check here for reference https://documentation.onesignal.com/docs/ios-native-sdk ant those are available options in latest OneSignal iOS SDK.
Android should be fine, no need to change anything. To be honest I have not try yet and iOS gives trouble.
from nativescript-onesignal.
@elconix Good news again;
Here is final example which works and Device is receiving push notifications properly. No fancy stuff haven't been added, you can check out links in comments for more details and available parameters. I can help with implementing them.
As you already probably know, you have to enable background notifications in Xcode project.
// Onesignal SDK Reference: https://documentation.onesignal.com/docs/sdk-reference#setloglevel-method
// Onesignal SDK available parameters: https://documentation.onesignal.com/docs/ios-native-sdk
if (application.ios) {
const MyDelegate = (function (_super) {
__extends(MyDelegate, _super);
function MyDelegate() {
_super.apply(this, arguments);
}
MyDelegate.prototype.applicationDidFinishLaunchingWithOptions = function (application, launchOptions) {
console.log("Application data: " + application);
try {
console.log('Onesignal starts here:', TnsOneSignal);
TnsOneSignal.initWithLaunchOptions({ kOSSettingsKeyAutoPrompt: true, kOSSettingsKeyInAppLaunchURL: true, kOSSettingsKeyInFocusDisplayOption: 2, kOSSettingsKeyProvidesAppNotificationSettings: true });
TnsOneSignal.setAppId("xxxxxxx-xxxxxx-xxxxxxxx-xxxxxxxx-xxxxxxxxxxxxxx");
// It is important to call this for any user response. Default iOS option (allow and deny) will be provided. No need for any fancy stuff
// funCallback is callback function and it wont work without it
TnsOneSignal.promptForPushNotificationsWithUserResponse(funCallback());
function funCallback(permission) {
console.log("Permission selection callback:" + permission);
}
} catch (error) {
console.log("Error: ", error)
}
return true;
};
MyDelegate.prototype.applicationDidBecomeActive = function (application) {
console.log("Application is activated: " + application);
};
MyDelegate.ObjCProtocols = [UIApplicationDelegate];
return MyDelegate;
})(UIResponder);
application.ios.delegate = MyDelegate;
}
For the reference, here are typings available in this nativescript plugin: https://github.com/roblav96/nativescript-onesignal/blob/master/typings/OneSignal.ios.d.ts
Check the line starting with declare class OneSignal extends NSObject {
What ever is available here: https://documentation.onesignal.com/docs/ios-native-sdk may not be available in OneSignal.ios.d.ts. OneSignal has updated Parameter list and names, implementation as well.
Forked version: https://github.com/markosole/nativescript-onesignal
from nativescript-onesignal.
this works with android @markosole have you tested in both platforms?
from nativescript-onesignal.
Ok @markosole reinstalled the plugin as the link https://github.com/markosole/nativescript-onesignal
Tested in simulator looks fine, waiting for testflight to publish the version for trying in device.
Android does not work, used the documentation you have in the link: https://github.com/markosole/nativescript-onesignal and it sends the following error when asking for the same code working in ios for person id:
System.err: TypeError: TnsOneSignal.getDeviceState is not a function
Let me know how your android compilation works out.
Thanks
from nativescript-onesignal.
THis is my code for getting person id:
// OneSignal
if(application.ios){
if(TnsOneSignal.getDeviceState()) {
console.log('Onesignal personid: ', TnsOneSignal.getDeviceState().userId);
}
}
if(application.android){
if(TnsOneSignal.getDeviceState().isSubscribed()) {
console.log('Onesignal personid: ', TnsOneSignal.getDeviceState().getUserId());
}
}
Ios working, android sending the error:
System.err: TypeError: TnsOneSignal.getDeviceState is not a function
from nativescript-onesignal.
Ok @markosole awsome, IOS finally working in device and everything ok.
Only now the android issue, did you try it?
Thanks
from nativescript-onesignal.
What issue you have? Example for Android I've posted works fine. I see you are using getDeviceState, there is something different for getting state. I will have a look into one of mine older projects. Let me know If you still have problem with it.
from nativescript-onesignal.
@elconix Here is android sample (I haven't tested for a year or so) which should work. The part you need is status.getSubscriptionStatus().getUserId());
The parameter/class/function TnsOneSignal.getDeviceState
does not exists in Android, it's. Onesignal Android SDK is using different methods and they have different names too.
var TnsOneSignal = require("nativescript-onesignal").TnsOneSignal;
if (application.android) {
application.on(application.launchEvent, function (args) {
try {
//console.log('TnsOneSignal', TnsOneSignal);
if (appSetting.NotificationsEnabled()) {
TnsOneSignal.startInit(application.android.context).init();
TnsOneSignal.setSubscription(true);
// ID OneSignal
var status = TnsOneSignal.getPermissionSubscriptionState();
console.log("Andoid push ID: " + status.getSubscriptionStatus().getUserId());
// do something with status ID
} else {
TnsOneSignal.startInit(application.android.context).init();
TnsOneSignal.setSubscription(false);
}
// Sunscribe
// # TnsOneSignal.startInit(application.android.context).init();
} catch (error) {
console.log('error', error);
}
})
}
Device state or subscription status, what exactly u need?
from nativescript-onesignal.
from nativescript-onesignal.
Sorry for late reply, I will test it ASAP when get chance. For now, remove appSetting.NotificationsEnabled() part as that's something what I built in for checking phone settings and opt-in / out option. You can replace it with if(1==1).... just for test.
I'll fire up my PC in 2-3 days and test on Android. @elconix
from nativescript-onesignal.
from nativescript-onesignal.
from nativescript-onesignal.
Hello Marko any news about android?
…
On Sun, Jan 10, 2021 at 6:43 PM Moises Vega @.> wrote: Thanks I will wait, as I have a apk working before the ios changes, Thanks On Sun, Jan 10, 2021 at 6:37 PM Marko Solomun @.> wrote: > Sorry for late reply, I will test it ASAP when get chance. For now, > remove appSetting.NotificationsEnabled() part as that's something what I > built in for checking phone settings and opt-in / out option. You can > replace it with if(1==1).... just for test. > I'll fire up my PC in 2-3 days and test on Android. @elconix
Hi @elconix sorry I did not have time to try it. It's def on my list to do as I have to update android versions too. I'm stuck on other project right now. I'll be back here as soon as I get chance, I did not forget about u.
from nativescript-onesignal.
Does this problem exist in NS 7+ only? I am on
"@nativescript/core": "^6.5.19",
from nativescript-onesignal.
It's same thing starting from 6.5 and newer. It's mainly problem in new SDK and plugin haven't been updated to fulfill those updates / changes. Do you have problem with Android as well?
@elconix I still did not have chance to try. I have two apps waiting to be updated.
from nativescript-onesignal.
@markosole
I haven't tried the plugin on any apps yet but was exploring the options on how to use Onesignal with Nativescript.
However, I will be starting with Android so I also will require a fix.
Are there other options then this plugin?
from nativescript-onesignal.
Related Issues (20)
- Please, can someone help changing TS code to JS for NS Core ? HOT 6
- failed to run npm run build HOT 1
- User not subscribing HOT 2
- Not compatable for Android on NS CLI5+ HOT 19
- How to register and recieve push notification? HOT 8
- Expose OneSignal Api for asking notification permission HOT 1
- Android crash lot of devices
- Plugin wont work with Nativescript-Javascript project HOT 1
- Android version 9.0 no working
- Firebase breaks the app after installing OneSignal, plugin conflict
- can't register although app starts on iOS HOT 1
- Fatal Exception: android.app.RemoteServiceException
- NotificationExtenderService [HELP]
- Upcoming issue with iOS 13 HOT 3
- v.1.0.8 not working with tns 5 -- maven misplaced twice, no manifestPlaceholder, FirebaseApp error HOT 3
- Cannot read property 'toLowerCase' of undefined HOT 5
- Identifier invalid format on iOS13
- TS2420: Class 'MyDelegate' incorrectly implements interface 'UIApplicationDelegate' HOT 8
- [iOS] Terminating app due to uncaught exception 'NativeScript encountered a fatal error: TypeError: Attempted to assign to readonly property.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nativescript-onesignal.