IBM Worklight - Cannot register to event source callback with an existing alias. The alias is already in use for event source - ios

I am using IBM Worklight 6.0.0 and testing on iOS 7 device.
I have the following js error:
Cannot register to event source callback with an existing alias: 'myPush'. The alias is already in use for event source 'PushEventSource'.
On device, when I login, logout then login again. (error appear the second time)
On the client side, my code is:
if (WL.Client.Push){
WL.Client.Push.onReadyToSubscribe = function(){
WL.Logger.debug("onReadyToSubscribe");
WL.Client.Push.registerEventSourceCallback(
"myPush",
"PushAdapter",
"PushEventSource",
pushNotificationReceived);
if (isPushSubscribed() == false) {
doSubscribe();
}
};
}
Is there something wrong with my code?
Is it because I should call "WL.Client.Push.registerEventSourceCallback" only once?
Any other solution?

You are not allowed to register an alias more than once as the error message shows. The error isn't that harmful, since regardless of the error message you can still receive push notifications (you may want to test this to be sure).
If you want to avoid the error message you have two options:
Ensure that the call to WL.Client.Push.registerEventSourceCallback
is called only once per app session, regardless of whether or not
the user has logged out.
Make a call to WL.Client.Push.unsubscribe when the user logs out to
clear the binding from the alias to the event source.
I'd suggest going with option 1. Push notification is tied to the device, not the user. Unless you plan on changing the event source alias for different users, there is no point in unsubscribing.

Related

QuickFIX/J - how to handle End Of Stream

I am new to QuickFIX/J.
Creating initiator using websocket(frontend-angular, backend-Springboot websocket). Using w.3.
I would like to handle session expired issue. When the FIX server session is expired, it is sending Logout with reason session deactivated. That works fine for already connected connection/session.
Now, after this, trying to initiate connection, it keeps calling back logout and toAdmin with repeating event/error on screen log (as event) "Disconnecting, End Of Stream encountered".
I would like to handle this scenario and want to capture this in my code so that proper message to UI will be sent.
I don't know which QuickFIX/J version you are using, but on versions up to 2.2.0 you could implement the quickfix.SessionStateListener in your application and utilize its onDisconnect() callback.
If you are even using version 2.3.0 you could also use onConnectException() which will handle some additional scenarios that the first callback does not cover.

Swift - register and re-register push notifications

Im trying to find a way to de-authorise users for push notifications when they log out from an app Ive found this function UIApplication.shared.unregisterForRemoteNotifications() which aparently works however I never see notifications being disabled, I also read in the documentation that it should not be used often or something to that effect, I basically want to have a toggle button in my app where the user clicks it one way and gets the standard enable notifications popup and another way to disable notifications on the fly, Im not a native swift developer so any pointers welcome
Also is it possible to attach a callback to this to know if it executes successfully, Im trying the following but get the error Argument passed to call that takes no arguments
UIApplication.shared.unregisterForRemoteNotifications() { (result, error) in
if let error = error {
call.error("Error", error)
} else if let result = result {
call.success([
"deregister": true
])
}
}
Edit: I found this which says its not possible to toggle on and off Change push notifications programmatically in Swift
With that in mind does this mean that the standard for devices is that:
1) when a user log out of their account they can still receive notifications.
2) When a user creates a new account on the same app it uses the same token and so receives notifications from the old account ?
3) when a user sells their phone and another guy/gal downloads the same app that they will receive notifications from that other users account (in terms of 3rd party push service one signal, aparently you dont need to refresh the player id)

Ti.Facebook doesn't open authorize with FB app installed

EDIT: DEAR PEOPLE FROM THE FUTURE, trey-jones has fixed this issue by implementing setLoginBehavior, FBSDKLoginNative seems to have issues on FB's end not with the module.
Environment:
MacOS X 10.10.5
Ti SDK 5.1.1.GA - 5.1.2.GA
iOS 9.2
Ti.Facebook 5.0.0 - 5.0.1
My project settings (tiapp.xml) are fine (it works on every other case on both iOS and Android).
Code I'm using to invoke the login:
var fb = require('facebook');
fb.initialize();
fb.authorize();
If the Facebook app is installed to the device the fb.authorize() doesn't open up. I did not see any iOS system level messages when this happened either.
Has anyone else had luck using fb.authorize with the new sdk on iOS devices WITH the app installed. With no fb app on the system it correctly opens the browser based view.
EDIT: I have managed a workaround for this (it is not pretty) based on the fact that login works with AppC's KitchenSink.
The workaround is to add a Ti.FB loginButton to the code, doesn't matter if its not visible, initializing this will fix whatever is causing custom login's .authorize() to not work.
//Workaround button:
if(OS_IOS){
var fbHaxBtn = fb.createLoginButton({
readPermissions: ['email'],
visible: false
});
}
//It needs to be added to the window/doesn't need to be visible though
$.login_window.add(fbHaxBtn);
//Then in our custom button's code, we can fire as normal:
function doLoginClick{
fb.initialize(); //I was having unexpected issues dropping this line on Android, although the docs say its deprecated.
fb.authorize();
}
Will keep this ticket updated if/when this thing gets a formal fix.
This is my second answer on this question. I believe that my original answer offers some value to the conversation and that is why I am leaving it, but it still did not consistently solve the problem of the facebook authorization not working.
The consistent solution turned out to be modifying the official Ti.Facebook module. I will submit a pull request for this change (1 line), but for now, you can get the working module here:
Source
Pre-built
This consistently allows users to authorize by explicitly setting the login behavior to use the browser, rather than the native facebook app through fast app-switching. This is actually the intent of Facebook's developers.
I was unable to determine what is causing it to fizzle when trying to use the native app to login - it should try the next option, which is the browser - but this works, and doesn't require a TiFacebookButton either.
I hope it helps someone else!
EDIT: This answer does not solve the original question. I have left it here in case it helps with related difficulties using the Ti.Facebook module. See my other answer, to actually solve the problem. END EDIT
I commented above, but after doing so encountered some more strange behavior, with the result being that I could not reliably use the workaround given (fbHaxButton). I want to explain what was happening in my case, and show my own workaround (which is also not pretty). It's possible that the root cause is the same for both of us.
I have not bothered with Android yet, so this answer is specific to iOS.
When I started this process, I came to the conclusion that authorize was correctly opening the facebook website in safari to allow authorization, but was not firing the login event upon returning. To handle this I had already implemented the following:
facebook = require('facebook');
Ti.App.addEventListener('resumed', function (e) {
var launchOptions = Ti.App.getArguments();
if(!launchOptions.url) {
return console.warn('Ignoring resume event with no url argument.');
}
// this lib = https://github.com/garycourt/uri-js
var URI = require('vendor/uri'),
uriComponents = URI.parse(launchOptions.url),
expectedScheme = 'fb',
expectedHost = 'authorize';
// I would like to be more specific about the uri, but we are limited
// in Titanium, and this will allow us to pretty certain
// that FB is sending us back to our app
if(uriComponents.scheme.search(expectedScheme) < 0 || uriComponents.host !== expectedHost) {
return console.warn('Resume event received, but scheme is incorrect. Ignoring.');
}
// synthesize login event
facebook.fireEvent('myapp:login', {
success: 1,
token: facebook.getAccessToken(),
uid: result.id
});
});
facebook.addEventListener('myapp:login', function onFacebookAuth(e) {
facebook.removeEventListener('myapp:login', onFacebookAuth);
if(!e.success) {
// do fail action
}
// do success action
});
facebook.initialize();
facebook.authorize();
So, originally I was firing and listening for an event called 'login', which the facebook module supposedly (according to the docs) will fire after authorization is complete.
In my case, this event was being fired while my app was in the background, after authorize was called, but before the user actually clicked 'OK' in facebook. My listener would respond to this event (logging, etc), but seemed to occur in a separate thread, or somehow otherwise become disconnected from my app, as it never passed its result along to the UI. I am using Q.js (kriw-kowal) and I belive this is where the disconnect is occuring.
Ceasing to listen to 'login', and simply handling my own synthesized event has fixed my issue.
I felt that this was very difficult to explain. If you have feedback about that, and how I can be more clear about what I believe is happening, or if you believe that I have reached wrong or incomplete conclusion, let me know - I'll try to update this answer to be better.

Monaca Push Debug App

I am working on an app using Monaca where I need to be able to push notifications to users of the app. I tried getting the monaca push back-end working, and that wouldn't work, the app didn't register. I then moved to using the standard cordova plugin, so I can push directly from my servers, without using monaca's back-end. when I call the init function, normally a register event will fire, this works fine when I build the app. However I very much want to get the custom debugger working, I am able to build the custom debugger, and I see the plugin properly installed. Also the init function gets called, as soon as it is called I get the standard IOS security alert to grant the app permission, however the register event is not fired, therefore I am unable to get the device ID to push to the custom debugger app. Has anyone been able to use push notifications with the custom debugger application?
Best,
Peter
(https://github.com/phonegap/phonegap-plugin-push)
P.S, i calls to set the badge count setApplicationIconBadgeNumber works fine in the debugger. I think this is something simple, maybe with the certs? I dont get any errors fired, no notifications no clues using the standard debugger, how can I hunt down what the issue is?
I can get it work using ngCordova, which is AngularJS integration.
http://ngcordova.com/docs/plugins/pushNotifications/
Then, inject it like
var app = ons.bootstrap('myApp', ['onsen', 'ngCordova']);
Get back to me if you need further clarification.

iOS: How to run web service without open application after installed in iPhone

How to run web service without open application
I need to run an service without open the app.
Once app closed from background also it must be run service.
Its an security app like anti theft functionality.
Can anybody help to run service without open app ?
As far as I know you can not, from a browser, check if an app is installed or not.
But you can try redirecting the phone to the app, and if nothing happens redirect the phone to a specified page, like this:
setTimeout(function (){
window.location = "https://itunes.apple.com/appdir";
}, 25);
window.location = "appname://";
If the second line of code gives a result then the first row is never executed.
Hope this helps!
You can check the "Implementing long-running background tasks" section from Apple document.
or
You can use by local notification to do that. But this not check every time. You set the time to where you will check a particular event.
Here is the tutorial for creating Local Notification step by step.

Resources