I would like to manually check if there are new updates for my app while the user is in it, and prompt him to download the new version. Can I do this by checking the version of my app in the app store - programatically?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Could I create “Call” button in HTML 5 IPhone appl
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Xcode: Is there a way to change line spacing (UI L
- Unable to process app at this time due to a genera
Just use ATAppUpdater. It is 1 line, thread-safe and fast. It also have delegate methods if you would like to track user action.
Here is an example:
Optional delegate methods:
Coming From a Hybrid Application POV, this is a javascript example, I have a Update Available footer on my main menu. If an update is available (ie. my version number within the config file is less than the version retrieved, display the footer) This will then direct the user to the app store, where the user can then click the update button.
I also get the whats new data (ie Release Notes) and display these in a modal on login if its the first time on this version.
The Update Available method can be ran as often as you like. Mine is ran every time the user navigates to the home screen.
Callback: Apple have an API, so very easy to get
My code proposal. Based on the answers by @datinc and @Mario-Hendricks
You should of course, replace
dlog_Error
with your logging func call.This kind of code structure should prevent your app from crashing in the event of an error. For fetching the
appStoreAppVersion
is not imperative, and should not lead to fatal errors. And yet, with this kind of code structure, you will still get your non-fatal error logged.Can I suggest this little library: https://github.com/nicklockwood/iVersion
Its purpose is to simplify the handling of remote plists to trigger notifications.
Here is my version using Swift 4 and popular Alamofire library (I use it in my apps anyway). Request is asynchronous and you can pass a callback to be notified when done.
Usage is simple like this:
Swift 4
We can use the new
JSONDecoder
to parse the response from itunes.apple.com/lookup and represent it with Decodable classes or structs:We can also add other properties to
AppInfo
in case we need thereleaseNotes
or some other property.Now we can make an async request using
URLSession
:this function receives a completion closure that will be called when the request is completed and returns an
URLSessionDataTask
in case we need to cancel the request, and can be called like this: