TodayViewController recreated every time Notification Center is shown - ios

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.

Related

react-native Mark items as they leave the screen in scroll view

I am writing an iOS app (just iOS for now, so I don't need to consider other platforms at the moment) in React Native.
I have a screen in my app that is a ScrollView of items that was retrieved from a server and I'd like to mark each item as "read" as it passes out of the top of the screen for the first time (i.e. mark as read on scroll type functionality). Once an item has been marked as read there you can mark it as unread but through other actions not related to scrolling.
I cannot for the life of me figure out a good way to do this. Ideally the items themselves would be able to detect whether or not they have disappeared off the top of the screen and just update the server that way, but I can't seem to find if that's possible (I easily could have missed something in the docs but I don't think so).
At the moment my solution is calculate how far down the ScrollView is, divide that by the height of each item (which is static for now... I don't know what I'll do when it becomes not static, if ever), and that's how many items I need to mark as read. At that point I do logic to determine if the local item has already been marked as read and if not I update the local item and send an update to the server.
A previous solution was to just update the server on each item, but that seemed like it got out of hand too quickly because you can scroll pretty fast and each item needs to be marked as read accurately.
The server api calls are idempotent, so sending multiple updates for the same item, while not great, is also not the end of the world. Also, I am running this in the emulator on my Mac and I haven't yet tested it with a real device (I have one, but I am still in kind of early stages of development).
I am happy to provide any other information needed!
The onViewableItemsChanged prop will return a list of items who's visibility has changed. Keep in mind that this visibility is decided by the viewabilityConfig prop
https://reactnative.dev/docs/sectionlist#onviewableitemschanged

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

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!

Fill the View Controller with elements/objects from web/cloud swift

I have a TableViewController which is connected to a empty-"template" viewController. I would like to make each cell responsible for its own interface/design.
In other words: the viewController has all elements placed (like UIImage, UILabel, UIText, etc.) and each time when specific cell is selected the viewController starts to fill with specific images/resources. Moreover, it would be great if the resources will be taken from web or cloud (in order to not save everything in the application itself).
So, I imagine it somehow like this:
Flow sketch
The problem is that I deal with this for the first time, and tried to find different ways to solve this problem (in terms of implementation), therefore I would like to ask: does this idea can be implemented in this way or probably there is more reliable way, and which techniques or technology can be used for this realization?
Thank you!
You can do it in multiple approaches. It totally depends on the architecture you have been following.
You can use react/ key-value observing and set the keys when you get a response.
Alternatively, for a very small app or a POC, I would use alamofire as my network manager and as soon as I get a response, I would set the labels. I would use the image extension in alamofire to set the images as it takes more time to download.
I would want to know the exact problem you are facing to help you out. Generic discussion are not normally encouraged here.

Making dynamically updating content in a UITableView accessible for VoiceOver

I'm trying to make my app more accessible and so far the standard accessibility things like labels and hints are doing wonders. I'm hitting a problem however with dynamically updating content that's displayed in a UITableView.
Each row of the table updates every second or so, but if I try to create each cell's accessibilityLabel at this point then I find that there is a problem with the VoiceOver reading out the selected label keeps interrupting itself as the label contents changes so the system just starts reading the label content from the beginning again (actually an odd quirk shows the voice over sometimes works correctly for the first cell that was selected, but upon selecting a new cell this bug returns).
I've tried to see if there's anyway to try and understand whether VoiceOver is currently active but as far as I can see there is only a notification posted when VoiceOver finishes
UIAccessibilityAnnouncementDidFinishNotification
There's no equivalent notification for when VoiceOver begins. So there's no way for my TableViewController to know that VoiceOver is currently active and that it shouldn't update any accessibilityLabels.
I'd hoped I could at least detect that one of my TableView cells was the selected accessibilityElement using the
accessibilityElementIsFocused
method. However in all my testing I've not been able to see this reliably fire for a custom UITableViewCell.
I also tried implementing the getter for accessibilityLabel for my custom cell hoping this may work, but sadly the same behaviour occurs.
The only solution I'm left with is a user configurable frequency for dynamic content accessibility updates, say 5, 10, 20 seconds... which can block me updating my label until I know that the last changed content would have definitely been read out. Actually even this could be interrupted if the user chose to select a cell at say 8 seconds after the last update, 2 seconds in for a 10 second limit and the label would update causing the voice over to restart.
Has anyone any ideas of how best to handle this dynamic updating content? I'm presuming the tableview cells are complicating matters a little, but in general I just don't understand how apple expects you to handle dynamic content. All it needs to solve this is another notification
UIAccessibilityAnnouncementDidStartNotification
Or even better a method to enquire as to whether VoiceOver is currently active. But I don't seem to be able to find any!
Thanks for your time, would really appreciate any tips on this. Cheers!
You want to do two things. First you want to take advantage of the "Updates Frequently" trait. This should improve the behavior of the app when the content is on.
This should help a lot. Then you alse need to provide a way for user to halt the updating content. Independent of whether you do the above, this is an absolute requirement to satisfy WCag 2.0 guideline 2.2.2.

how to make a view appear only if is the first time? [duplicate]

This question already has answers here:
Show screen on first launch only in iOS
(8 answers)
Closed 9 years ago.
Thanks in advance .
I wanna make a view appear only if the application is launch for the first time, I have work with a similar code to display Alerts, but I can find a way to make it with a Storyboard view ? For example my idea is : in the image below I have 7 buttons so I want the user to select which Country/Button they wanna use after this first time launch (it will be a button where they can change it back ) and how can I save the value of the button (the one that the user choose) so that every time the app launches again it goes straight to the one they selected when the app was installed ?
Thank you .
There are two pretty easy solutions I can think of.
First, in both instances, you'll be duplicating much of the same logic you say you've used previously in displaying a UIAlertView.
Option 1: Have the view with buttons that should only be displayed once as the first view. In the viewDidLoad method, check whether the app has been launched before and a button has been selected. If a button has been selected before, just go ahead and perform the segue straight from the viewDidLoad into the rest of the app.
Option 2: This time, instead of starting with the 1-time view, start with the standard first view. Check if the app has been launched before or not, and if it has, perform a modal segue into the view where they select a button (otherwise just don't perform the segue).
I'm certain there's a more elegant solution to get this work in a better way, but this is a pretty simple implementation that should be quite easy to get working.
I would us an NSUserDefault here. First check for the presence of a preference for the key you specify. If it doesn't exist you'll want to show the region selection view. If it does exist just use the region stored in the preference.
This way, if the preference every gets deleted or lost, the logic will be small enough that the user can recover fairly quickly.

Resources