I want to send a push notification to the user when a value in my firebase database change. this is my database
{
"Battles" : {
"00000111-062B3333-4046-4FB4-AA37-C2B05853E497" : {
"BattleProgress" : "",
"Player1" : "lzsPuNwHbIZI1J8k40FspYRV4XQ2",
"Player2" : "tHNBif9csWNCOuftAGLAqvLWNUw1",
"Score" : "0-0",
"Turn" : 1
}
},
"users" : {
"lzsPuNwHbIZI1J8k40FspYRV4XQ2" : {
"Coins" : 1,
"Dollars" : 0,
"FBID" : “ID”,
"GamesLost" : 0,
"GamesWon" : 0,
"name" : “Name”
},
"tHNBif9csWNCOuftAGLAqvLWNUw1" : {
"Coins" : 0,
"Dollars" : 0,
"FBID" : “ID”,
"GamesLost" : 0,
"GamesWon" : 0,
"name" : “Name”
}
}
}
So lets say, the value of "Turn" changes, then I want a push notification sent out to the player whos turn it is. But how can I check if the value of "Turn" changes when the user shuts down the app?
I've read a bit about Firebase Cloud Messaging, but cant seem to find the answar...
You can do this with Firebase using Cloud Functions. Check out https://firebase.google.com/docs/functions/use-cases and https://firebase.google.com/docs/functions/database-events for more information.
Related
We have an AR project (built in Unity) that's running 24/7 on a number of iPads Pros (12.9, gen 3) in a museum. It's been live for 2.5 years now. We've always had the occasional freeze (on iOS 13 and below), but lately they have gotten exponentially worse (on iOS 14.4.2 and 14.6).
The problem manifests as follows, at completely random times: our app keeps running in the background (we can hear sound effects and see database activity continuing), but it stops getting redrawn, causing the screen to freeze on whatever frame was drawn last.
We're getting a gpuevent .ips log at freeze time (see below), which has information about an IOSurface being blocked by IOFence. There's very little info online about these logs though, so we're sort of stuck with the analysis. From what little I can find, it seems like we have some resource, possibly a texture buffer, that gets accessed by two processes simultaneously, causing one of those processes (the one responsible for drawing the screen) to get killed by the OS. Does that sound plausible? And if so, how do we find out where in our code the issue is triggered?
Can anyone here interpret this log better than we can, or does anyone have suggestions as to our next steps?
{"bug_type":"284","timestamp":"2021-07-10 10:51:30.00 +0200","os_version":"iPhone OS 14.6 (18F72)","incident_id":"C3ABD477-2A61-4D43-A3B1-25D7CCD706E6"}
{
"process_name" : "hats",
"registers" : {
},
"timestamp" : 1625907090,
"analysis" : {
"iofence_list" : {
"iofence_num_iosurfaces" : 1,
"iofence_iosurfaces" : [
{
"iofence_current_queue" : [
{
"iofence_acceleratorid" : 1,
"iofence_backtrace" : [
-68148358856,
-68148357636,
-68144533400,
-68144532380,
-68144496896,
-68144598792,
-68144425788,
-68144434312
],
"iofence_direction" : 1
}
],
"iosurface_id" : 243,
"iofence_waiting_queue" : [
{
"iofence_acceleratorid" : 2,
"iofence_backtrace" : [
-68148358856,
-68148357636,
-68146420632,
-68154559340,
-68146423972,
-68146427004,
-68146495056,
-68154290536
],
"iofence_direction" : 2
},
{
"iofence_acceleratorid" : 1,
"iofence_backtrace" : [
-68148358856,
-68148357636,
-68144533400,
-68144532380,
-68144496896,
-68144598792,
-68144425788,
-68144434312
],
"iofence_direction" : 1
}
]
}
]
},
"fw_ta_substate" : {
"slot0" : 0,
"slot1" : 0
},
"fw_power_state" : 0,
"fw_power_boost_controller" : 0,
"guilty_dm" : 1,
"fw_power_controller_in_charge" : 0,
"fw_cl_state" : {
"slot0" : 0
},
"fw_perf_state_lo" : 1,
"fw_ta_state" : {
"slot0" : 0,
"slot1" : 0
},
"signature" : 625,
"fw_power_substate" : 4,
"command_buffer_trace_id" : 490782964,
"fw_perf_state_select" : 0,
"restart_reason" : 7,
"fw_3d_state" : {
"slot0" : 0,
"slot1" : 0,
"slot2" : 0
},
"fw_gpc_perf_state" : 0,
"fw_perf_state_hi" : 1,
"fw_power_limit_controller" : 7,
"restart_reason_desc" : "blocked by IOFence"
}
}
I am rebuilding a social media app like Instagram.
My user can decide to delete their account and then I would like to automatically delete all things belonging to the user.
Most of the stuff I can delete easily, but things like posts is where I struggle because the uid is just a sub child of the key where the post is saved into.
My Database tree:
"Feed" : {
"es5fIbnKFpX4szcCbroUqHjJg6E3" : {
"-KjTBFFE5QzktG1IT5u0" : true,
"-KjTHFNe1RRS8Ly6bKsA" : true,
"-KjY30xwWA2IJBwlvyzf" : true
}
"myPosts" : {
"jlkRoaucY6Q4GBkzhor5yAAl97I2" : {
"-KjTBFFE5QzktG1IT5u0" : true,
"-KjTHFNe1RRS8Ly6bKsA" : true,
"-KjY30xwWA2IJBwlvyzf" : true
}
"posts" : {
"-KjTBFFE5QzktG1IT5u0" : {
"bookmarkCount" : 0,
"caption" : "Toll",
"commentCount" : 1,
"creationDate" : 1.494081403379004E9,
"hoursSinceUpload" : 0,
"likeCount" : 0,
"photoUrl" : "https://firebasestorage.googleapis.com/v0/b/funcloud-8e84e.appspot.com/o/Posts%2F76192CBE-55F0-4907-889A-849E196D5796?alt=media&token=de675609-4b73-411d-b402-f1ff3db64f79",
"ratio" : 1.502732240437158,
"score" : 16.38698994684219,
"uid" : "jlkRoaucY6Q4GBkzhor5yAAl97I2"
},
"-KjTHFNe1RRS8Ly6bKsA" : {
"bookmarkCount" : 1,
"bookmarks" : {
"jlkRoaucY6Q4GBkzhor5yAAl97I2" : true
},
"caption" : "Traumhaft",
"commentCount" : 0,
"creationDate" : 1.494082976550228E9,
"hoursSinceUpload" : 0,
"likeCount" : 2,
"likes" : {
"es5fIbnKFpX4szcCbroUqHjJg6E3" : true,
"jlkRoaucY6Q4GBkzhor5yAAl97I2" : true
},
"photoUrl" : "https://firebasestorage.googleapis.com/v0/b/funcloud-8e84e.appspot.com/o/Posts%2F306BF7E1-9FEF-493A-ABF8-C0E061E8648F?alt=media&token=128bdd90-023a-49ac-8361-19c02c631183",
"ratio" : 1.502732240437158,
"score" : 166.6491847103437,
"uid" : "jlkRoaucY6Q4GBkzhor5yAAl97I2"
}
"users" : {
"es5fIbnKFpX4szcCbroUqHjJg6E3" : {
"email" : "user3#mail.de",
"profilText" : "Schreib etwas über dich",
"profileImageUrl" : "https://firebasestorage.googleapis.com/v0/b/funcloud-8e84e.appspot.com/o/profile_image%2Fes5fIbnKFpX4szcCbroUqHjJg6E3?alt=media&token=ce8d8722-39bc-457a-8149-e51c837ef0a3",
"username" : "Blondine",
"username_lowercase" : "blondine"
}
My function where I delete data
static func removeUserData() {
let user = Auth.auth().currentUser
let uid = API.User.CURRENT_USER?.uid
Database.database().reference().child("users").child(uid!).removeValue()
Database.database().reference().child("Feed").child(uid!).removeValue()
Database.database().reference().child("Favoriten").child(uid!).removeValue()
Database.database().reference().child("LikesFromUsers").child(uid!).removeValue()
Database.database().reference().child("post-comments").child(uid!).removeValue()
Database.database().reference().child("notification").child(uid!).removeValue()
Database.database().reference().child("followers").child(uid!).removeValue()
Database.database().reference().child("following").child(uid!).removeValue()
Database.database().reference().child("LikesCommentsFromUsers").child(uid!).removeValue()
Database.database().reference().child("comments").child(uid!).removeValue()
user?.delete(completion: { (error) in
if let error = error {
print(error.localizedDescription)
} else {
print("success")
}
})
}
I would love to iterate through all posts and look for every post which contains the uid of the current user and then delete these posts.
Thanks in advance :)
I would build a server task that can run this asynchronously, removing the responsibility from the mobile device. If the app crashes or loses connection, you'll get a severely broken data set. You need to be able to run it in a stable and verifiable environment. This inherently solves your problem as well, since now you can (at your server's leisure) cycle through and delete all posts owned by the user.
As far as your app is concerned, you'll just need to call a single API after validating that the user wants to delete their account, and voila.
I'm having problems with JSON and Postman when I'm trying to test camera settings. Every time when I change settings, the picture is always the same. If I change shutter speed to value 0.0002 (which should be shutter speed 1/5000) the result is the same as on 0.1 (1/10).
This is my JSON:
{
"name" : "camera.setOptions",
"parameters" : {
"sessionId": "SID_0001",
"options" : {
"clientVersion" : 2,
"_autoBracket": {
"_bracketNumber": 3,
"_bracketParameters": [
{
"exposureProgram" : 1,
"shutterSpeed": 0.1,
"iso": 400,
"exposureCompensation" : 0,
"whiteBalance" : "_colorTemperature",
"_colorTemperature": 5100
},
{
"exposureProgram" : 1,
"shutterSpeed": 0.1,
"iso": 320,
"exposureCompensation" : 0,
"whiteBalance" : "_colorTemperature",
"_colorTemperature": 5100
},
{
"exposureProgram" : 1,
"shutterSpeed": 0.1,
"iso": 1600,
"exposureCompensation" : 0,
"whiteBalance" : "_colorTemperature",
"_colorTemperature": 5000
}
]
}
}
}
}
Once I submit those settings using camera.execute.setOptions, the reply says that the settings have been successfuly changed, yet when I try to take a picture using camera.execute.takePicture, the picture turns out to be the same as on default settings. Am I missing something? Thanks in advance!
When you are using _autoBracket option you have to use camera.startCapture with parameter "_mode" : "bracket" and not camera.takePicture as when taking ordinary photos
{
"name" : "camera.startCapture",
"parameters" : {
"_mode" : "bracket"
}
}
I'm going to create app to share photo albums, using firebase.
Now I've issue with securing common objects.
My data object is
"Album" : {
"AbAY6YVhy6MLyvVjyYC517v62o22" : {
"-KeD0I9C-esXW2zA4uH_" : {
"backgroundPattern" : 0,
"collaboratorsIDS" :
[ "cS5O4Klt8CXrrKLJPVkHMaSTltW2","J55nZlr4SSPHL5GW7c7yrUkbAUl1", "LQ5mNECXAMQi9AoLCXh8GMsihf12" ],
"date" : "2017-03-02",
"direction" : 2,
"imageUrl" : "",
"ownerID" : "AbAY6YVhy6MLyvVjyYC517v62o22",
"scrapBookID" : "-KeD0I9C-esXW2zA4uH_",
"title" : "Test"
}
}
And question is, how to set .read and .write rules for albums. Main point is that collaboratorsIDS is user ID's that should have access to album.
"Album": {
"$albumId" : {
"$pushKey" : {
".read":"data.child('collaboratorsIDS').val().contains(auth.uid)"
}
}
With this, you can allow access to your node for collaboratorsIDS
When running the code below, I get an empty response, even though the corresponding data is there:
self.ref?.child("play-data/calories/GC5g4RUmy0WTTL5w3jSobefa9Ft2").
queryOrdered(byChild: "parentId").
queryEqual(toValue: "-KcpS62MR-73MozKJEVt").
observeSingleEvent(of: .value, with: { (snapshot) in
print("ITEMS \(snapshot.childrenCount)")
}) { (error) in
print("ERROR :: \(error)")
}
The data looks like this:
{
"play-data" : {
"calories" : {
"GC5g4RUmy0WTTL5w3jSobefa9Ft2" : {
"-KcpTSo0KrnNIzmAAD9O" : {
"endTime" : 1486955567572,
"id" : "-KcpTSo0KrnNIzmAAD9O",
"parentId" : "-KcpS62MR-73MozKJEVt",
"startTime" : 1486955550331,
"value" : 1.328500509262085
},
"-KcpTT---0Zu-0eTd4a8" : {
"endTime" : 1486955627572,
"id" : "-KcpTT---0Zu-0eTd4a8",
"parentId" : "-KcpS62MR-73MozKJEVt",
"startTime" : 1486955567572,
"value" : 4.62333345413208
},
"-KcpTT-1SvZrScKdceLC" : {
"endTime" : 1486955636994,
"id" : "-KcpTT-1SvZrScKdceLC",
"parentId" : "-KcpS62MR-73MozKJEVt",
"startTime" : 1486955627572,
"value" : 0.7260898947715759
}
}
}
So based on the data, it should print 3 but does 0. Permissions are configured correctly since I have Android and web implementations that work fine with this data. Any ideas?
OK, looks like this was the result of my local and cloud versions of the data being out of sync and therefore the inconsistent results during testing (where I had to run tests, replace the post-test data with an older backup, repeat) I fixed these issues by adding this line to my init code:
ref?.child("play-data").keepSynced(true)
I already had this one before:
db?.persistenceEnabled = true
Where ref and db are references to FIRDatabaseReference/FIRDatabase.