$http service is not working on iPhone browsers, but its working fine on other devices browsers, after debugging what I have found is $http request is not reaching to server back-end.
Here is my login function using in controller:
function login() {
$http.post(ENV.apiUrl+'/users/login', { email: $scope.username, password: $scope.password }).then(handleSuccess, handleError);
}
function handleSuccess(res) {
console.log(res);
}
function handleError(err) {
console.log(err);
}
Related
I am trying to use sockets in sailsjs.
I have an action which just returns the socketId
module.exports = async function exampleAction(req, res) {
if (!req.isSocket) {
console.log("not a socket req");
return res.badRequest();
}
sails.sockets.getId(req);
return res.json({ socketid: sails.sockets.getId(req) });
};
and in routes.js:
"GET /label/exampleaction": {
action: "label/example-action",
isSocket: true,
},
I'm trying to connect to it from nuxt.js using Websocket :
this.connection = new WebSocket("ws://localhost:1337/label/exampleaction");
This gives me an error:
WebSocket connection to 'ws://localhost:1337/label/exampleaction' failed:
What am I doing wrong?
First of all, try to make this controller simpler, only for tests.
Like this:
async function onConnect(req, res) {
const socketId = sails.sockets.getId(req);
res.json(socketId);
}
'POST /connect': { controller: 'TestController', action:'onConnect' },
For client part, i recommend use the sails browser library: https://github.com/balderdashy/sails.io.js
You can use it in your nuxt app, it is all javascript, no mistery.
Sails Docs have a specific section with more details: https://sailsjs.com/documentation/reference/web-sockets/socket-client
My issue is the login with the email and password function works fine on android but on iOS, the promise is never returned ( nor failed ) when correct credentials are provided but it fails if I provide incorrect credentials. The login works on iOS with live reload simulating on an iOS device, but when installed with test-flight or via xCode promise is never returned nor rejected.
How can I debug it further or know what the underlying issue is?
onSubmit: async (values) => {
try {
const auth = getAuth(firebaseApp);
auth.setPersistence(browserSessionPersistence);
// Never called on IOS
auth.onAuthStateChanged(() => {
console.log('I am here', auth.currentUser);
if (auth.currentUser) {
updateIsAuthenticated(true);
}
});
const userCred = await signInWithEmailAndPassword(auth, values.email, values.password);
//Never runs
console.log('After Success', userCred);
} catch (error) {
// Runs when provided with false credentials
setError('Error: Authentication failed');
console.error('An error Occurred');
} finally {
console.log('Running Finally');
}
},
});
I am trying to test my code with
.controller('AppCtrl', function ($scope, $ionicModal, $cordovaOauth, $localStorage, $location) {
$scope.login = function() {
$cordovaOauth.facebook("APPID", ["email", "read_stream", "user_website", "user_location", "user_relationships"]).then(function(result) {
$localStorage.accessToken = result.access_token;
alert("facebook login correctly");
$location.path("/profile");
}, function(error) {
alert(error);
console.log(error);
});
};
But all the time getting error:
cannot authenticate via a web browser
I am using ionic and cordovaOauth, when I am trying to test the app with android I don't get any response.The question is how can I debug it really with simulator or something easily like PhoneGap app, I tried to work with phone gap but can't know how can I debug it.
I've met the same problem and I have found this : https://github.com/nraboy/ng-cordova-oauth/issues/46
Basically, you should test your code in an emulator not in a browser.
i'm tring to implement quickblox chat in my ios App but it doesn't work.
I'm using ionicframework
in my index i have:
<script src="/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="/lib/quickblox/quickblox.js"></script>
<script src="/lib/quickblox/quickblox.chat.js"></script>
my controller is:
var params, chatUser, chatService;
params = {login: 'xxxxxx', password: 'xxxxxx'};
QBAPP = {
appID: xxxxxx,
authKey: 'xxxxxx',
authSecret: 'xxxxxx'
}
QB.init(QBAPP.appID, QBAPP.authKey, QBAPP.authSecret);
console.log('step1')
// QuickBlox session creation
QB.createSession(params, function(err, result) {
console.log('step2')
if (err) {
console.log(err.detail);
} else {
chatUser = {
id: result.user_id,
pass: params.password
};
connectChat();
}
});
function connectChat() {
chatService = new QBChat({onConnectFailed: onConnectFailed,
onConnectSuccess: onConnectSuccess,
onConnectClosed: onConnectClosed
});
// connect to QB chat service
chatService.connect(chatUser);
}
/* Callbacks
------------------------------------------------------*/
// Connection is failed
function onConnectFailed() {console.log('doh')}
// Connection is success
function onConnectSuccess() {console.log('happy')}
// Connection is closed
function onConnectClosed() {}
if i test this on browser everything is ok, but when I test on the ios simulator nothing work and the console doesn't show any error. It stop at step1. any Ideas? thanks
I'm developing a REST API using Codeigniter-restserver for a mobile applications in Phonegap.
Since Phonegap loads index.html using file://, my API should support CORS. And I'm new to this CORS.
I've set headers in libraries/REST_Controller.php
header("Access-Control-Allow-Origin: *");
header('Access-Control-Allow-Headers:Origin, X-Requested-With, Content-Type, Accept');
And I'm using Backbone.js.
Here is my Controller
// This can be removed if you use __autoload() in config.php OR use Modular Extensions
require APPPATH.'/libraries/REST_Controller.php';
class Prop extends REST_Controller
{
public function __construct()
{
parent::__construct();
$this->load->database();
}
function property_get()
{
...
}
function property_post()
{
...
}
function attach_image($file_type)
{
if($this->post($file_type) != ""){
save_base64_image($file_type,$this->post($file_type));
$this->email->attach($_SESSION[$file_type]);
}
}
function property_delete()
{
...
}
function share_post()
{
$email_id = $this->post('emailid');
$config['mailtype'] = "html";
$this->email->initialize($config);
$this->email->from('myid#gmail.com', 'mobile app');
$this->email->to($email_id);
$this->email->subject('subject');
$this->email->message('message');
if ( ! $this->email->send() )
{
$this->response("Internal server error.", 500);
}
else
{
$result = new stdClass();
$result->message = 'Email has been sent.';
$this->response($result, 200); // 200 being the HTTP response code
}
}
public function send_post()
{
var_dump($this->request->body);
}
public function send_put()
{
var_dump($this->put('foo'));
}
}
Here's my jQuery ajax call.
$.ajax( {
url: PMSApp.apiUrl + "/share/format/json",
type: 'post',
dataType: "json",
contentType: "application/json; charset=utf-8"
})
.done(function(response) {
console.log(JSON.stringify(response));
})
.fail(function(response) {
console.log(JSON.stringify(response));
})
.always(function(response) {
console.log(JSON.stringify(response));
});
I'm able to access this /share/format/json API with POSTMAN, chrome extension, but not with file:// or localhost://.
EDIT:
I've also tried changing share_post() to share_gett(), It worked. But i need it in POST.
I'm stuck on this for the past 48 hours. Tried many solutions, but nothing helped me with this issue. Please help me.
Phonegap provides option to whitelist your webservice domain. It is set up the access origin in config xml
http://docs.phonegap.com/en/2.3.0/guide_whitelist_index.md.html
You have to start Chrome with Access-Control-Allow-Origin
This thread:
https://superuser.com/questions/384871/overriding-access-control-allow-origin-restriction-in-google-chrome
Check this tread:
Origin is not allowed by Access-Control-Allow-Origin