iOS SwiftUI widget issue, the widget load old/default data when is added to lockscreen / home on a physical device - ios

forgive me if I say nonsense, I have been fiddling with swift for just over 2 months ...be patient :-)
So, I have a problem with the widget and I don't understand what it depends on, maybe it happened to someone and it could help me.
Everything works perfectly, app and widget update, except one (damned) thing: when I add the widget from the gallery for the first time, it loads me the default data.
Let me explain: when selecting from the widget gallery the snapshots are updated correctly; when I select it it flashes on an old view (something I would say imperceptible even if it bothers me personally) and then, no one knows why, it loads the default data when it is added to the home / lockscreen, as if the userdefaults were empty .
On the simulator it loads it well, on my device it doesn't (iPhone 7).
I would like to understand, from you who know more than me, how the views are divided at the juncture of the gallery:
from what I understand, when I see the preview from the gallery it is the getSnapshot: in that context, I load the data from the Userdefaults store to get an updated preview; the same goes for the placeholder since I don't have to fetch anything and therefore I should have the result immediately (but I didn't really understand where the placeholder would appear .. maybe it's that flash I hate so much?).
in getTimeline I do the same, I load the data from the store and then in the for of the timeline I recall them.
has it ever happened to anyone?
I would like to post code but I do not have the possibility for various reasons .. i'm really sorry.
thank you very much to those who will try to help me!

Related

iOS Core Data sometimes is delayed in loading

I have an app that's been available in the app store for a few years that uses Core Data. When the app is launched, the user is taken to the app's home screen where a few buttons are shown. Clicking any of the buttons takes the user to another screen that shows data that is loaded from Core Data in a UITableView (each button takes the user to different data). This is basic functionality that's been working in my app just fine the entire time the app's been available.
At some point last year, I noticed that at random times, the data saved in the app sometimes wouldn't load right away. The first time this happened, I clicked one of the buttons and was taken to a blank screen. I went back to the home screen and tried other buttons, and each screen was blank, so I thought all of my data had been wiped somehow. I proceeded to head back to the home screen and just sat there thinking for about 15 seconds, then I clicked one of the buttons again, but this time the data appeared. All of the other screens had data now as well.
I haven't updated the app in quite a while, so my code is unchanged. I don't recall there being a new iOS release around the time I started observing the issue, but it's possible.
This has happened a few more times since I first discovered it (3 or 4 times total over the last 6 months), but there seems to be no pattern at all. Once the data finally loads during these situations, it always loads right away from that point forward. This has made it impossible for me to debug it, because I can't force this situation to happen (99% of the time the data loads immediately).
Has anyone encountered this before, or have any recommendations on how to proceed? I've witnessed this on the Simulator and once on an actual device.
Random delays in updating your UI are a classic sign of attempting to update the UI from outside the main queue. It'll work, usually, but it may be delayed, and the delays won't be consistent. Make sure that when you try to update the UI, you're on the main queue. Use DispatchQueue.main.async() if necessary.
Assuming that you're using Xcode 9, make sure the main thread checker is turned on. That'll help you find this kind of problem when you're running the app from Xcode. Go to the target pop-up at the top of Xcode's window and select "Edit scheme...". In the "Run" section of the window, go to "Diagnostics" and make sure "Main Thread Checker" is turned on.

Swift / Parse: Checking to make sure the data loaded

Got an app written in Swift that creates a PFObject, saves it and then goes to another view controller. At that view controller, the data is read from Parse.com and displayed on the page. In the simulator and on my iPad Air 2, the app runs fine. On older iPads, however, it crashes at the new view controller. I think it's a simple matter of trying to show the data before it's loaded. I've put in a delay that stops the crash, but I'd like a more elegant solution.
I'd like to be able to check to see if the data is loaded (that's easy - if data != nil) but if it is nil, how do I get it to sit and wait for it to load? Any suggestions?
I'm a noob so feel free to talk slowly... ;)
Thanks!!!

TodayViewController recreated every time Notification Center is shown

When trying to develop a Today Extension for iOS 8 I found a weird issue. It would seem that the View Controller I'm using is being recreated every time the user opens Notification Center. This means that there is no data retention and hence no way for me to know if the extension needs to update or not.
The main reason for wanting to do this is that I want to preserve the height of the widget (Using preferredContentSize). The problem is that when the view loads this value always gets reset which leads to the widget jumping around in size. The Stocks widget is an example of how it's supposed to work and they've obviously solved it so there has to be some way of retaining the data between different "sessions". I can also tell from the debugger that the process continues to run, so it's just down to something in Apple's code forcing the View Controller to be recreated.
My question is, is this a bug? Or is it based on some setting or some property that I'm missing? Or is it maybe just the way it's supposed to work? If so, what is the workaround?
That's the way they work. Save your information to the device so you can reload it the next time you launch, along with the update time so you know if it's out of date. For small amounts of data, just use NSUserDefaults. For larger amounts save to a file, CoreData, sqlite, etc.

IOS Orientation fix doesn't work all the time

I am developping a swipe gallery for mobile devices. Users can change images by sliding the screen, as any normal images gallery in most iPhone app.
Here is a demo:
http://daviddarx.com/stuffs/work/custom/swip/
To debug the iOS orientation bug (which let the content zoomed when you change the orientation), I used the only library that correct that:
http://scottjehl.github.com/iOS-Orientationchange-Fix/
Unfortunately, this library is working perfectly most of the time, but it happens to fail and not work correctly. This happen around 1 time on 10 times, and the result is then the same as if the library wasn't here.
This is not a huge problem on most of the mobile and responsive website, as the user can manually dezoom and then get back to the normal display.
But the problem here is that I had to disable the zoom function, to make my system work correctly. So, when the bug happen, once on 10 times, the gallery is then just bugged and stay like that....
So, here are my questions:
-do you know any other library that manage that bug fix, and is 100% completely reliable?
-if not, do you know a way to correct the used library to get a 100% support rate?
-if not, do you have any idea or solution for me?
Thank you in advance for your help!
David
There's an outstanding pull request on Scott Jehl's repo that uses slope detection instead of absolute values which seems to not suffer from the intermittent-ness of the original solution.
https://github.com/PeterWooster/iOS-Orientationchange-Fix/

TTLauncherView move item to other page

I have a TTLauncherView in my ios app. I have allowed users to edit and move their items around, however it does not appear that you can move the item from one screen to another, does anyone know how to do this?
that's looks like another a bug in three20 library. I just checked an old app of mine and moving items from page to page works fine. It means it might be another iOS 5 issue.
You can open a bug for it in http://github.com/facebook/three20, hopefully someone will fix it.
If I'll get around to it, i'll check it and fix it. I have a few apps using it, so I might need to do that.
I experienced a similar problem. It seems to be a bug just for the first icon on that page (i.e. creating a new page) - adding just add another icon to that page works fine (at least for me).
You can get around this bug by dragging the icon to the new page and releasing it on the first row (on the top of the page!). This isn't really satisfying, but perhaps a good starting point.

Resources