How to update app from Today extension - ios

I have requirement to update application containing viewcontroller from todayextension widget view controller when app is in either in background/foreground state. Lets assume.
App containing viewcontroller contains list of information. Next press on home button app goes to background state.
Now open widget and show list of information as shown in app containing viewcontroller in TodayExtensionViewcontroller.
If you update any information in TodayExtensionViewController same information I want to replicate in App containing viewcontroller when app goes from background to foreground state.

Your app and Today extension have to be able to share data.
First of all, you have to add the "App Group" capability to the App IDs of both your app and your Today extension so that they can access shared data.
The easiest way to share data is to use shared user defaults, but it is also possible to share a persistent Core Data store, for example.
Every time your app enters the foreground, it should check if the shared data has changed (or just reload its data from the shared store) so that changes made in the widget take effect.
Every time the user changes data in your app (or at least before the app becomes "inactive"), the app should update the shared data so that the widget is up to date.
This guide by Apple is a good starting point. Moreover, there are lots of good tutorials available that explain "data sharing" in much more detail.

Related

Multiple WatchKit Apps For 1 iOS App

According to the Apple Watch Programming Guide, developers are only allowed to include 1 glance in their AppleWatch app. This creates a bit of a challenge for me since my app is an aggregate of different types of data so I'm not sure which data set to include in the glance.
That being said, could I get around this by creating multiple AppleWatch apps for my iOS app which would then allow me to create a single glance for each AppleWatch app?
No. Confirmed one Watch app per iOS app.
There is no support for multiple WatchKit apps per iPhone app at this
time.
- Apple's WatchKit Evangelist
You can implement multiple Glance views depending on the user's context (time and location) using WKInterfaceGroups and hiding/unhiding when necessary.
See my answer to the exact same question here https://stackoverflow.com/a/28214768/3588917
Will a timer work for you? For example, when a certain time elapsed, you can change the UI of the glance to show a different type of data? When a user taps a glance, you will be able to tell what data is showing in the glance at the time and pass relevant contextual data and redirect them to an appropriate interface controller?
"When the user taps a glance, Apple Watch launches the corresponding WatchKit app. Normally, launching the app displays its main interface controller. If you want to display a different interface controller at launch time, call the updateUserActivity:userInfo: method from your glance interface controller and use it to provide contextual information about what the glance is doing. At launch time, your app can use that contextual data to display a different interface controller."

iOS Assets Library: permanent unique key for photos(identify photos between multiple runs)?

Say I have an app which allows user to pick some images from assets library.
When running for the 1st time, user picks some photo, at the 2nd run, when user wants to pick photos, I'd like to set the photos user picked last time as already selected.
How do I identify photos between multiple runs of my app?
iOS apps usually don't get terminated, but get sent to background - state will be unchanged when getting back to foreground
For case your app get's terminated anyway, you can store data in NSUserDefaults, CoreData, the file system or the keychain. In your case it sounds like NSUserDefaults would be a good choice. Don't forget to restore last states on app start.

What to do when the user enables or disables the iCloud support in the app Settings Bundle?

I am targeting iOS7 and I use iCloud with an UIManagedDocument. I would like to know what to do in these two cases:
1) First case: App first launch
It's the first launch, when we do not know yet if the user wants to use iCloud or not and we should assume he doesn't want to use it until we ask him. Once we'll find out, his choice will be stored in the app Settings Bundle and he will be able to change his mind later.
When my app launch, the first view that appears triggers the UIManagedDocument init with [[UIManagedDocument alloc] initWithFileURL:url]. It does this because it should know how many rows it has to display in its table.
At this point, it is the first launch, and I still have to ask to the user, I assume he does not want to use iCloud so the UIManagedDocument is initialized without the persistentStoreOptions set (NSPersistentStoreUbiquitousContentNameKey and NSPersistentStoreUbiquitousContentURLKey).
The file is then created on the disk with
[UIManagedDocument saveToURL: URL
forSaveOperation: UIDocumentSaveForCreating
completionHandler: ^(BOOL success){
if(success){
//Do something with the document
}
}];
then the view appears. Since it is the first launch, I should ask the user if he wants to use iCloud or not.
I show an UIAlertView from [viewDidAppear:animated]
If he answers "NO", everything is already ok. But what should I do if he says "YES"??
Should I close the UIManagedDocument and migrate the DB or is it enough to set the NSPersistentStoreUbiquitousContentNameKey and NSPersistentStoreUbiquitousContentURLKey in the document's persistentStoreOptions?
2) Second case: a couple of days later the user changes his mind
The user did choose to enable iCloud but after some day he changes his mind. He switches to NO the iCloud option in the app settings bundle. When the app launches I check for a change in this option and I find that it has switched from YES to NO. As I understood from the hints I got on SO, the correct path should be to display an UIAlertView asking him if he wants:
a) Keep the documents on the device
b) Delete the documents from the device
c) Keep using iCloud
What should i do for the options a) and b)?
A DB migration for option a) and recreate the DB from zero for option b)?
The way you're using the term "migration" is a little confusing, as incrementing the Core Data model from one version to a new one is also called migration. I assume you're just talking about "migrating" from iCloud to local only or vice versa.
In your first case, I wouldn't create the UIManagedDocument until the user has made a choice. If the user wants to use iCloud, all you have to do is take that and open it and you don't have to worry about closing/removing the local document (which is now pointless).
In the second case, if the user chooses option A, copy the file from iCloud to local, then remove it from iCloud. Option B means "remove from iCloud, I don't want it anymore". If you still want to continue using Core Data locally, create a new document for it. C, of course, would do nothing, just dismiss the alert.
Typically there are two places to check whether iCloud settings have changed and/or to check or open any files:
1) in the AppDelegate method application:didfinishlaunchingwithoptions, and
2) in the AppDelegate method applicationwillenterforeground
In addition if you register for iCloud account change notifications you can respond to them.
This allows you to organise things before your view starts trying to display any core data items. Opening or Migrating a file may take some time so you may have to display some other activity indicator view while this is being performed.
I would not create the document in the view that displays data because the call to open the document is performed asynchronously and until the completion handler runs you don't know when it's going to complete. Rather you should use the completion handler to launch this view because then you know it's safe to start accessing the core data objects.
More details on how to achieve UIManagedDocument & iCloud Integration here.

How to send in-app announcements to people using my iOS app?

I have a couple apps on the Apple App Store and would like some way to send announcements to users whenever I want. Basically, I want to remotely change the text of an IUAlertview and only trigger it to appear if I want it to (upon app opening and only if I updated the message).
So far I have no problem making the IUAlertview appear on when the app opens, and I can easily program an NSUserDefault flag to only make the IUAlertview appear under certain circumstances, but really have no idea how to dynamically change the UIAlertview text without resubmitting my app to Apple continuously.
Can someone please explain how this is done? Thanks!
One way to do this is to have your app periodically (or upon each launch) check a file on a website that you control and if there is changed text (or a version number, or newer date than the last time an alert was displayed) there, then display that changed text in your UIAlertView.

QuestionAboutCreating IOS SDK in order to hook one app onto another app

I got one question, Need help. Thanks.
Question: One App have already been created which will delivered Ads based on data, right now, I want to hook this app to another app but without wrapping the whole App to the second App, which i searched would create a static framework, but not that in that, the second App will just deliver one simple ID,and retain one banner space for showing the upcoming Ads, then in my App-server, It will only return the Ads to the second App.
How to do this ?

Resources