Cloud.Users.update(hash, function (e) { if (e.success) { Ti.API.info('Succesfully updated user profile for user ' + e.users[0].username); } else { UI.alertError('Failed updating user profile ' + (e.error && e.message) || JSON.stringify(e)); } });
Cloud.Users.logout(function (e) { if (e.success) { Ti.App.Properties.setString('sessionID', Cloud.sessionId); // set to null Ti.API.info('Successfully logged out'); Ti.App.fireEvent('user_status_change'); Ti.App.fireEvent('loggedOut'); } else { UI.alertError('Failed logging out user: '******'stoppedLoading'); });
/** If the telephone is not connected to the internet, this is not actually an error */ /** btw, error -1004 is when there is network but it can’t find the internet * -1009 is when there is no internet connection (is supposed to be found by getNetworkTypeName, but apparently not always) * -1003 is when a server with this hostname could not be found * -1001 is when the server times out (probably a connection problem as well) */ Ti.API.info("tried to delete photos while not connected to the internet"); return; } UI.alertError('Failed deleting photo: ' + JSON.stringify(error)); } }); delXhr.open("DELETE", url); //delXhr.setRequestHeader('X-HTTP-Method-Override', 'DELETE'); // in iOS we can send a DELETE request directly,
onerror: function(error) { if (Ti.Network.getNetworkTypeName() === "NONE" || error.code === -1009 || error.code === -1003 || error.code === -1004 || error.code === -1001) { /** If the telephone is not connected to the internet, this is not actually an error */ /** btw, error -1004 is when there is network but it can’t find the internet * -1009 is when there is no internet connection (is supposed to be found by getNetworkTypeName, but apparently not always) * -1003 is when a server with this hostname could not be found * -1001 is when the server times out (probably a connection problem as well) */ Ti.API.info("tried to request photos while not connected to the internet"); return; } UI.alertError('Failed loading photos through network: ' + JSON.stringify(error)); } });
}, function (e) { if (e.success) { var user = e.users[0]; Ti.App.Properties.setString('sessionID', Cloud.sessionId); Ti.App.Properties.setString('username', user.username); Ti.App.Properties.setString('userid', user.id); Ti.App.fireEvent('user_status_change'); Ti.App.fireEvent('loggedIn'); var dialog = Ti.UI.createAlertDialog({ message: L('username') + ': ' + user.username, ok: 'OK', title: L('welcome') }).show(); } else { if (e.message.toLowerCase().indexOf("already taken") !== -1) { UI.alertError(L('username_taken')); } else { UI.alertError('Failed creating user: '******'stoppedLoading'); });