smorel / ResourceManager

ResourceManager : Synchronize your application resources from dropbox to the app and experience dynamic reload on simulator and devices.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ResourceManager allows you to synchronize your resource in the app running on a device or emulator while your editing them on your Mac. Whether it is an image, a sound, a nib, an AppCoreKit stylesheet or layout and even string files, the ResourceManager let your see the changes you're making in your assets live on your devices. Connect several devices with different form factor or idiom simultaneously with one or several resource managers. This is useful when you're working in team and want to get your UI up-to-date while other are working on it. Or only connect your Mac with your devices if you don't trust your colleagues It's up to you!

With the ResourceManager framework, combined with AppCoreKit and a few lines of code, all this is possible.

How does it work?

ResourceManager is a framework designed to improve your productivity while developing iOS applications. The main objective is to synchronize multiple resource repositories and work with the most recent version of each. By resources, we mean everything that you'd like to embed into your application, such as images, nibs, strings files, config files, json, AppcoreKit stylesheets and layouts, sounds.

ResourceManager provides simple APIs similar to NSBundle to get the paths of the most recent resources from the various resource repositories.

Repositories can be defined as bundles, as well as a peer connection to a deamon running on your Mac. The Resource Manager provides APIs similar to NSNotificationCenter to register for notifications when files are updated. As soon as a file gets saved in one or several remote repositories, the files will get downloaded to the application's cache directory if needed and a notification is sent to your application to update. You can also get notified of file additions and changes by observing file extensions.

This framework should be used during the development process as you do not want to impact your user experience with files updating at runtime! You can easily disconnect sync mechanism but still use the APIs to get the resources from the application main bundle by not setting a shared RMResourceManager.

ResourceManager supports ios version 7 and more as well as the following architectures: armv7, armv7s, arm64 and i386 for the simulator.

Sample Usage

1. Initializing the resource manager:

1.1. Synchronizing Resources via network with your Mac

In your application delegate:

#import < ResourceManager/ResourceManager.h >

- (id)init{
    self = [super init];

    RMPeerResourceRepository* peerRepository = [[RMPeerResourceRepository alloc]init];
    RMResourceManager* rm = [[RMResourceManager alloc]initWithRepositories:@[peerRepository]];
    [RMResourceManager setSharedManager:rm];

    //Do your stuff
}

On your Mac:

We provide a mac app named RMPeerDeamon, that scans changes for assets in specifified folders. To run this app, you can build it and run it as a command line tool in your terminal.

Command line requiers to specify the directories to watch and the app bundle identifier that is related to these assets.

example:

open ~/RMPeerDeamon.app -directory "MyProjectFolder/Resources" -bundle-identifier "com.mycompany.myapp"

1.2. Synchronizing your resource from your XCode project's directory (Working in Simulator Only)

In your target plist:

add a string entry with key "SRC_ROOT" and value "$SRCROOT/$PROJECT/"

In your application delegate:

#import < ResourceManager/ResourceManager.h >

- (id)init{
   self = [super init];
   
    //Comment or remove the following code when you want to deactivate the sync mechanism
    NSString* projectPath = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"SRC_ROOT"];
    RMBundleResourceRepository* lr = [[RMBundleResourceRepository alloc]initWithPath:projectPath];
    lr.pullingTimeInterval = 1;
    
    RMResourceManager* rm = [[RMResourceManager alloc]initWithRepositories:@[lr]];
    [RMResourceManager setSharedManager:rm];
    
    //Do your stuff
}

2. Forward requiered callback to the resource manager:

In your application delegate:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
    //Do your stuff ...

    //After :
    [self.window makeKeyAndVisible];

    [RMResourceManager handleApplication:application 
           didFinishLaunchingWithOptions:launchOptions];
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url 
                                       sourceApplication:(NSString *)sourceApplication 
                                              annotation:(id)annotation {
                                              
	[RMResourceManager handleApplication:application 
                                 openURL:url];
                                                
    //Do your stuff
}

3. Retrieving The most recent path for resource:

NSString* resourcePath = [RMResourceManager pathForResource:@"MyResource" 
                                                     ofType:@"myExtension"];
//Load the resource here using the "resourcePath" ...

4. Getting notified when this resource gets updated:

[RMResourceManager addObserverForPath:resourcePath 
                               object:self 
                           usingBlock:^(id observer, NSString *path) {
    //Load the resource here by using the last updated "path" ...
}];

As the manager keeps some weak references on the observer object, you must unregister from the resource manager when needed or at least when you object ("self" here) gets deallocated.

[RMResourceManager removeObserver:self];

5. Retrieving The most recent paths for resources with a specific extension:

NSArray* paths = [CKResourceManager pathsForResourcesWithExtension:@"mp3"];
//Do something with those files

6. Getting notified when these resource are updated or a new file is added with the specified extension:

[CKResourceManager addObserverForResourcesWithExtension:@"mp3" 
                                                 object:self 
                                             usingBlock:^(id observer, NSArray *paths) {
    //Do something with the up to date paths for all mp3 files.
}];

Like for a single path observation, do not forget to unregister your observer.

Installation

The recommended approach for installing ResourceManager is via the CocoaPods package manager, as it provides flexible dependency management and dead simple installation. For best results, it is recommended that you install via CocoaPods >= 0.19.1 using Git >= 1.8.0 installed via Homebrew.

Using CocoaPods

Adds the following lines in you PodFile

platform :ios, '7.0'

pod 'ResourceManager'

As a framework

Using ResourceManager in your own App (Pre-Compiled)

You can find a pre-compiled version of ResourceManager and sample integration in our sample repository at https://github.com/smorel/appcorekit-samples

  • Add the following frameworks and libraries dependencies to your project in the build phases settings:
Foundation.
Security, 
QuartzCore,
CFNetwork,
SystemConfiguration.
  • Adds the following link flags in your build settings (OTHER_LDFLAGS):
 -ObjC -all_load -weak_library /usr/lib/libstdc++.dylib

Compiling the framework

ResourceManager is built as a Static Framework. Static Frameworks are not natively supported by Xcode 5 or less and require some additional specifications to be compiled properly. You can skip this setup if using XCode 6 and more.

Copy the following file:

./static Frameworks.xcspec

To:

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Specifications

And

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Xcode/Specifications

IMPORTANT: You will have to copy this file each time you update Xcode to a newer version.

Using ResourceManager in your own App (Sources)

  • Drag'n'drop the ResourceManager project as subproject in Xcode.

  • Adds the ResourceManager.framework link dependency to your target in the build phases settings.

  • Add the following frameworks and libraries dependencies to your project in the build phases settings:

AppPeerIOS, (that can be found in this repository) 
Foundation,
Security, 
QuartzCore,
CFNetwork,
SystemConfiguration.
  • Adds the following link flags in your build settings (OTHER_LDFLAGS):
 -ObjC -all_load -weak_library /usr/lib/libstdc++.dylib

Compiling the API Documentation

ResourceManager provides a "Documentation" target that generate a docset using the public header files and the additional programming guides in the Documentation folder. This target is a script base on "appledoc". To install appledoc, follow the installation procedure here : https://github.com/tomaz/appledoc

Fully integrated with AppCoreKit

It has been designed to update directly to your device and not only the simulator like it was previously implemented in AppCoreKit. Several changes have been made to the AppCoreKit to fully integrate this new framework as a weak dependency and in a very efficient way. AppCoreKit provides the mechanism to automatically reload stylesheets and layouts, images, mappings, mock, localization files (.strings) and updates the UI as a consequence. Go to the AppCoreKit github repository and get the master branch to try the integration:

https://github.com/smorel/AppCoreKit

Credits

If you have any comments, suggestions, question or information request, please contact us at morel.sebastien@gmail.com.

License

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

ResourceManager : Synchronize your application resources from dropbox to the app and experience dynamic reload on simulator and devices.

License:Other


Languages

Language:Objective-C 98.0%Language:Ruby 2.0%