Powerful Google developer tools for immediate impact! (2023-24 C)
Parse - a mobile backend platform
1. Parse
A mobile backend platform
www.parse.com
Carlotta Tatti
Twitter: @thestubborndev
Email: carlotta.tatti@gmail.com
2. Cosa offre Parse?
• Una soluzione integrata per la creazione di
backend
• SDK per Android, iOS, Javascript, Unity 3D,
Windows 8, Windows Phone
• Endpoint REST
4. Inizializzazione dell’SDK
[Parse setApplicationId:@"APPLICATION_ID" clientKey:@"CLIENT_KEY"];
Creazione di un elemento
ParseObject gameScore = new ParseObject("GameScore");
gameScore.put("score", 1337);
gameScore.put("playerName", "Sean Plott");
gameScore.put("cheatMode", false);
gameScore.saveInBackground();
5. Creazione di un utente
ParseUser user = new ParseUser();
user.setUsername("my name");
user.setPassword("my pass");
user.setEmail("email@example.com");
// other fields can be set just like with ParseObject
user.put("phone", "650-253-0000");
user.signUpInBackground(new SignUpCallback() {
public void done(ParseException e) {
if (e == null) {
// Hooray! Let them use the app now.
} else {
// Sign up didn't succeed. Look at the ParseException
// to figure out what went wrong
}
}
});
9. Send a Push Notification
Esempio 1
ParsePush push = new ParsePush();
push.setChannel("Giants");
push.setMessage("The Giants just scored! It's now 2-2
against the Mets.");
push.sendInBackground();
Esempio 2
// Create our Installation query
ParseQuery pushQuery = ParseInstallation.getQuery();
pushQuery.whereEqualTo("injuryReports", true);
// Send push notification to query
ParsePush push = new ParsePush();
push.setQuery(pushQuery); // Set our Installation query
push.setMessage("Willie Hayes injured by own pop fly.");
push.sendInBackground();
11. Parse Social
• Signup tradizionale (username e password)
• Signup tramite Twitter o Facebook
• Gestione di tutto ciò che riguarda
l’autenticazione e la gestione degli utenti
(login, logout, password reset, email di
conferma etc..)
13. Login with Facebook
3.
ParseFacebookUtils.logIn(this, new LogInCallback() {
@Override
public void done(ParseUser user, ParseException err) {
if (user == null) {
Log.d("MyApp", "Uh oh. The user cancelled the Facebook
login.");
} else if (user.isNew()) {
Log.d("MyApp", "User signed up and logged in through
Facebook!");
} else {
Log.d("MyApp", "User logged in through Facebook!");
}
}
});
14. Login with Facebook
L’utente corrente è sempre accessibile:
ParseUser currentUser = ParseUser.getCurrentUser();
if (currentUser != null) {
// do stuff with the user
} else {
// show the signup or login screen
}
16. Cloud Code
• Codice server-side in Javascript
• Estensibile tramite moduli
• Possibilità di pianificare task periodici
17. Una funzione Cloud Code
Javascript
Parse.Cloud.define("hello", function(request, response) {
response.success("Hello world!");
});
Android
ParseCloud.callFunctionInBackground("hello", new
HashMap<String, Object>(), new FunctionCallback<String>() {
void done(String result, ParseException e) {
if (e == null) {
// result is "Hello world!"
}
}
});