ios


Wait saveInBackground Parse before viewDisappear


I would like to wait saveInBackground Parse method before the view disappears. Because the view following is using this data, but that doesn't have the time to refresh...
Here is my code :
-(void) viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
PFQuery *urlImage = [PFQuery queryWithClassName:#"urlImage"];
[urlImage whereKey:#"objectId" equalTo:#"IcK6mFChL7"];
[urlImage getFirstObjectInBackgroundWithBlock:^(PFObject *urlImageParse, NSError *error) {
if (!error) {
[urlImageParse setObject:self.photoURL.text forKey:#"URL"];
[urlImageParse saveInBackground];
} else {
NSLog(#"Error: %#", error);
}}];
}
Can I make this code in other place that viewWillDisappear:? Or maybe use MBProgressHUD?
viewWillDisappear is a place to execute code, knowing that the view is about to disappear. I believe what you are looking to do is run some action, prior to the view actually going away.
This part right here -> [urlImage getFirstObjectInBackgroundWithBlock:^
means that the code inside that block is going to run on a different thread. So what you are currently saying is, when the view is about to disappear, spin off this other thread and save something in the background, but continue on doing whatever you need to do, like make this view disappear. That's what you're telling the system. So it continues on, doing what it was going to do, not caring about the results of saving that object.
There is a reason that your view is about to disappear. Something happened in your app where the system is thinking it needs to close this view and present another one. It could be that you hit a back button, it could be that you clicked a save button, and at the end of that code, you are asking the system to pop this view off the stack. We really don't know with only the code you posted. What we can assume though, is whatever action was taken to make this view disappear, is where you should be trying to save this object, and you should probably be waiting for a response before you leave this view. If the next view is dependent on that information, then it doesn't make sense to dismiss this view, and present the next one, until you get a successful response that this object was saved. This is just an assumption though, since I don't understand what your app is doing or what is going on when you are trying to save this data, and what the next view looks like. I would say that typically, if you need this stuff to be saved, in order to continue on in your app, you should be saving this data and waiting for a response, to either display an error message to the user, or if successful, then move on to the next screen.

Related Links

Move a UILabel when changing to landscape
“show” segue inside UITabBarController & UINavigationController does not push
Deep linking in iOS 10 not working
Command /bin/sh failed with exit code 133 - CocoaPods error macOS Sierra
Bluetooth LE on iOS10 strange behavior
add handle to uiScrollView like in the screenshot
Xcode unexpectedly quit while reopening windows every time
How to set up UIBezierPath border for view in ios?
Trying to parse JSON in Swift, but get error
Crashlytics does not show crashes
Data out of sync using same account on different devices
How to stop every action in a GameScene in Swift/iOS
IOS App contains multiple storyboards with Objective C. How can i add more funcionality with swift by adding new storyboard with old?
AVPlayer sometimes fails to play video
NSURL works on initial load For AVPlayer but will not load on next run, why?
Type MyViewController does not conform to protocol 'STPPaymentContextDelegate'

Categories

HOME
ssis
oozie
svg
gwt
azure-search
pyqt5
apt-get
appium-ios
arm
svg.js
tsql
format
mvvm-light
http2
tin-can-api
microsoft-dynamics
py.test
apache-spark-sql
scope
editor
factory-girl
watchservice
web-audio
graphcool
servlet-filters
media-source
sfsafariviewcontroller
selenium-edgedriver
dsl
mediacodec
google-geocoder
webfocus
arduino-esp8266
shinydashboard
pymysql
pvlib
seh
ollydbg
spring-websocket
webcenter
azure-app-service-envrmnt
bcel
rights-management
compass-lucene
easy-digital-downloads
stateful
sweet.js
android-calendar
asyncsocket
attributerouting
jce
jvm-arguments
autogen
android-touch-event
android-camera-intent
mapr
zenity
sqlite-net
git-config
mit-scheme
turnjs
xendesktop
activity-diagram
visual-build-professional
formatter
menustrip
dms
isapi-rewrite
lidar
win32com
wgs84
laravel-forge
sejda
voting
xsb
android-print-framework
sqlhelper
ratingbar
mui
subdirectory
notifydatasetchanged
spread-toolkit
dotliquid
str-to-date
rte
jquery-data
speaker
cassette
blackberry-cascades
makumba
harvest
sticky-footer
cellid
ed
websolr
boost-gil
mate
soapheader
ssao
jtemplates
renderaction
indextank
program-transformation
queryanalyzer
database-dump

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App