Integrate reveal into your project from Xcode

Source: Internet
Author: User

Integrated reveal: Add reveal to your Xcode project

Add reveal to your Xcode project so that other members of your team can use reveal without any additional configuration.

warning : Never publish an app that contains reveal dynamic library files. Apple does not allow iOS apps that contain dynamically loaded library files to be published to the Apple store.

  1. Open your iOS project in Xcode.

  2. Start Reveal and select __help→show Reveal Library in finder__, which will open the Finder window and display a folder named *ios-libraries*.

  3. Drag the libreveal.dylib file into the Project Navigator panel in Xcode.

  4. In the __add to Targets__ dialog box that is displayed, __ uncheck all the target__. This ensures that Xcode does not connect to the dynamic library file at compile time. Optional step: Select __copy items If needed__, will copy the Libreveal.dylib to the project-if you do this, remember that when the update reveal to the new version, also follow the above steps to update the library file again .

  5. Click **finish**.

  6. In Project Navigator for Xcode, select your project, and then apply the following steps to all of the target reveal you want to match:

    1. In the __copy Bundle resources__ configuration area, add *libreveal.dylib*.
    2. In the **link Binary with libraries** configuration item:
      • If you already have *libreveal.dylib*, remove it--you should not connect the Dylib file at compile time.
      • If the following system framework and library files do not already exist, please add them:
        • Libz.dylib
        • Cfnetwork.framework
        • Quartzcore.framework
        • Coregraphics.framework-xcode typically includes this framework file in the project by default.
  7. In order to be able to dynamically load library files into the application on the device outside of debugger, you need to add code sign to the Libreveal.dylib file during the build process.

    Go to Target's __build phases__ tab and select the __editor→add Build phase→add Run script__ menu. In the Run script phase, add the following:

    set -eif [ -n "${CODE_SIGN_IDENTITY}" ]; then    codesign -fs "${CODE_SIGN_IDENTITY}" "${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}/libReveal.dylib"fi
  8. Add the following code to the appropriate class file in your project (for example, your UIApplicationDelegate ) and modify it to meet your needs:

    Swift:

    // MARK: - Revealfunc loadReveal() {    if NSClassFromString("IBARevealLoader") == nil {        let revealLibName = "libReveal"        let revealLibExtension = "dylib"        var error: String?        if let dylibPath = NSBundle.mainBundle().pathForResource(revealLibName, ofType: revealLibExtension) {            println("Loading dynamic library \(dylibPath)")            let revealLib = dlopen(dylibPath, RTLD_NOW)            if revealLib == nil {                error = String(UTF8String: dlerror())            }        } else {            error = "File not found."        }        if error != nil {            UIAlertView(title: "Reveal library could not be loaded",                      message: "\(revealLibName).\(revealLibExtension) failed to load with error: \(error!)",                     delegate: nil,            cancelButtonTitle: "OK").show()        }    }}

    Objective-c:

    #pragma mark-reveal#import <dlfcn.h>-(void) loadreveal{if (nsclassfromstring (@ "ibarevealloader") = = nil) {        NSString *reveallibname = @ "Libreveal";        NSString *reveallibextension = @ "Dylib";        NSString *error;        NSString *dylibpath = [[NSBundle mainbundle] Pathforresource:reveallibname oftype:reveallibextension];            if (dylibpath! = nil) {NSLog (@ "Loading Dynamic Library:%@", Dylibpath);            void *reveallib = Dlopen ([Dylibpath cstringusingencoding:nsutf8stringencoding], rtld_now);            if (reveallib = = NULL) {error = [NSString stringwithutf8string:dlerror ()];        }} else {error = @ "File not found."} if (Error! = nil) {NSString *message = [NSString stringwithformat:@ "%@.%@ failed to load with error:%@            ", Reveallibname, Reveallibextension, error]; [[[Uialertview alloc] initwithtitle:@ "Reveal Library could Not be loaded "Message:message delegate:nil cancelbuttontitle:@" OK "otherbuttontitles:nil] show]; }    }}

    warning : Do not call this method in the publish (release) build to ensure that only the *libreveal.dylib* is loaded in the Applied Debug (debug) build.

  9. A simple way to integrate is to -[UIApplicationDelegate application: didFinishLaunchingWithOptions:] invoke the method declared above in the method - (void)loadReveal to ensure that the reveal library is loaded as soon as possible.

    Swift:

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {    self.loadReveal()    return true}

    Objective-c:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{    [self loadReveal];    return YES;}

    tip : -[UIApplicationDelegate application: didFinishLaunchingWithOptions:] One of the benefits of loading a library before the method returns is that it will let the reveal service start automatically as the app starts.

  10. If you do not want the reveal service to start automatically as described above, you can start it manually, for example through a debug button. After the app starts, call loadReveal the method yourself, and then distribute a named IBARevealRequestStart NSNotification :

    Swift:

    func startReveal() {    NSNotificationCenter.defaultCenter().postNotificationName("IBARevealRequestStart", object: nil)}

    Objective-c:

    - (void)startReveal{    [[NSNotificationCenter defaultCenter] postNotificationName:@"IBARevealRequestStart" object:nil];}
  11. In Xcode, choose a scheme based on **debug** configuration to build and run your app.

    If everything works, switch to the Reveal app, where your app should appear in the drop-down list of app selectors. Check your app to make sure you see the app interface running in the emulator (or device) at this point.

Website address: Http://support.revealapp.com/kb/getting-started/revealrevealxcode

Integrate reveal into your project from Xcode

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.