Coder Social home page Coder Social logo

alfwatt / livebundle Goto Github PK

View Code? Open in Web Editor NEW
13.0 3.0 1.0 46 KB

NSBundle+LiveBundle is a category to provide dynamic updating of resources from your web server.

Home Page: https://istumbler.net/labs/

Objective-C 100.00%
macos ios foundation resources plist

livebundle's Introduction

LiveBundle

Keep your Resources Fresh

NSBundle+LiveBundle is a category which provides dynamic updating of resources from your web server.

Let's say you have a resource, any resource will do, but for e.g. a plist which contains a list of your companies products, their prices, and links to purchase them; which is stored inside MyApplication's bundle as a resource:

MyApplication.app/Contents/Resources/productTable.plist

And let's say you want to add a new product, or change a price for asale, or update a link, but don't want to release a new version of your app or write a web server that hosts an API or the code to support it?

LiveBundle provides infrastructure for hosting bundle resources on your web server at a URL that you specify, so that your app can check to see if there is an updated version of the resource avaliable for download:

https://exaple.com/support/livebundle/com.example.myapplication/productsTable.plist

LiveBundle makes a If-Modified-Since request to your server when the resource is requested. It then downloads the resource, and copies it into the users's Library folder (or it's sandboxed equivalent):

~/Library/Application Support/MyApplication/LiveBundle/com.example.myapplication/products_table.plist

And that's the path that your code sees when it asks for the resource:

NSString* livePath = [[NSBundle mainBundle] livePathForResource:@"productsTable" ofType:@"plist"];
NSDictionary* productsTable = [NSDictionary dictionaryWithContentsOfFile:livePath];

// Subscribe to be notified for updates to the file path (or just watch the file path yourelf):

[NSNotificationCenter。defaultCenter 
    addObserverForName:ILLiveBundleResourceUpdateNote 
    object:livePth 
    queue:nil 
    usingBlock:^(NSNotification *note) {
        productsTable = [NSDictionary dictionaryWithContentsOfFile:livePath];
        // update the ui...
    }];

The initial path is a link back to the resource in the application's bundle, once an updated version has been sucesfully downloaded the

This works well for data that changes on a weekly or monthly basis, the app should only check a URL once per launch, or as much as daily if it's running for a long time.

TODO Certificte Pinning Support on top of the existing SSL Nag

Support LiveBundle!

Are you using LiveBundle in your apps? Would you like to help support the project and get a sponsor credit?

Visit our Patreon Page and patronize us in exchange for great rewards!

Using LiveBundle in your App

  • include the LiveBundle.framework in your applications Resources/Frameworks directory
    • link the LiveBundle.framework to all the targets which produce bundles you would like to update
  • add a key to the Info.plist of all the NSBundles you want to update pionting to the web server
    • ILLiveBundleURLKey is the base url for the bundles resources
      • e.g. https://example.com/livebundle/
    • when calling livePathForResource: the URL is prepended to the resource requested
      • e.g. livePathForResource:@"resource.plist" is https://example.com/livebundle/resource.plist
  • add a UI element to disable LiveBundle if the user doesn't want updates:
    • bind the element's value to the NSUserDefaults key: ILLiveBundleDisableUpdates
    • checkboxes work well if you use NSNegateBoolean with the phrase Automatically Update Resources on Startup
    • it will be selected by default, and the user disabling will set the value to YES
  • deploy resources to your web server and always test before you ship!

TODO

  • <NSDictionary+LiveBundle.h> for plists loaded via livePlistFor:...
  • <NSImage+LiveBundle.h> for images loaded via liveImageFor:...

Releases

  • 1.2 - August 2024
    • Added tvOS build
    • Added +[NSBundle trashLiveBudles] to help with app reset tasks
    • Remove CircleCI build config
    • Nullability in NSDate+RFC1123
    • Use dispatch_once for static formatters
    • Move TODO items into README.md
    • Add LiveBundle (All) target for build testing
  • 1.1 - November 2017
  • 1.0.1 - 14 May 2016
  • 1.0 - 13 May 2016

License

The MIT License (MIT)

Copyright © 2015-2024 Alf Watt

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.