IOS Development notes-interface debugging artifact Reveal

Source: Internet
Author: User

IOS Development notes-interface debugging artifact Reveal

Reveal is one of the artifacts in iOS development tools. It can debug the application interface while the application is running. With Reveal, we can connect to the application and allow developers to edit various user interface parameters. The results will be immediately displayed on the user interface. Just like the debugging page provided by Web developers using the developer tools provided by the browser, reveal allows developers to debug the iOS app user interface without modifying code, re-building projects, and re-deploying applications.

Install Reveal

Reveal: http://revealapp.com/download/

Integration Guide

Integrating Reveal requires no code or header files. The repository is automatically loaded when the application is started, and the necessary Reveal services are started inside your application.

Three Integration Methods for static connection

Connecting Reveal static library files to applications is the easiest and quickest way to enable Reveal inspection.

Warning do not publish the Reveal library file along with the official application. The following steps will show how to build the configuration, and connect the Reveal static library file to the debugging build process only.

Open your iOS project in Xcode.

Start Reveal and selectHelp → Show Reveal Library in FinderThis will open the Finder window and displayIOS-Libraries.

SetReveal. framewZ restart? Http://www.bkjia.com/kf/ware/vc/ "target =" _ blank "class =" keylink "> vcms8L3N0cm9uZz4gzsS8/certificate =" "src =" http://www.bkjia.com/uploads/allimg/160322/04224B231-1.jpg "title =" \ "/>

In the displayedAdd to targetsIn the dialog box, select all targets that you want to integrate with Reveal. Optional steps: selectCopy items if neededReveal. frameworkCopy to project-if you do, remember to update the library file again when updating Reveal to the new version.

Click Finish.

Select the Build Settings tab and add the following configuration to the Debug configuration item of Other Linker Flags.

-ObjC -lz -framework Reveal

If you are using Xcode 7, make sure that the directory where Reveal. framework is located is in your project configuration item"Framework Search Paths. The specific content will look like this.

FRAMEWORK_SEARCH_PATHS = $(inherited) "$(SYSTEM_APPS_DIR)/Reveal.app/Contents/SharedSupport/iOS-Libraries"

Build and run your application in Xcode. If the application runs on a real device, make sure that the device is in the same Wi-Fi network as the Mac machine running Reveal.

If everything works properly, switch to the Reveal application. Your application will appear in the drop-down list of the application selector. Select your application to see the application interface running in the simulator (or device.

Dynamic Loading

Dynamic Loading allows iOS apps to load third-party libraries as needed during runtime. In this way, the library file does not need to be connected to the application's executable file, but is added to the application Bundle to load as needed during running. In this way, developers can completely control the loading of Reveal databases and start and stop their services in their personal applications.

Adding Reveal to your Xcode project allows other members of your team to use Reveal without any additional configuration.

Warning never release an application that contains the Reveal dynamic library file. Apple cannot publish iOS apps containing Dynamically Loaded library files to the Apple store.

Open your iOS project in Xcode.

Start Reveal and selectHelp → Show Reveal Library in FinderThis will open the Finder window and display a folder named iOS-Libraries.

SetLibReveal. dylibDrag the file to the Project Navigator panel in Xcode.

In the displayedAdd to targetsDialog box,Select all targets.. This ensures that Xcode does not connect to dynamic library files during compilation. Optional steps: selectCopy items if neededLibReveal. dylibCopy to project-if you do, remember to update the library file again when updating Reveal to the new version.

Click Finish.

InCopy Bundle ResourcesIn the configuration area, addLibReveal. dylib.

InLink Binary With LibrariesConfiguration item:

? If libReveal. dylib already exists, remove it -- the dylib file should not be connected during compilation. If the following system frameworks and library files do not exist, add them:
Libz. tdb CFNetwork. framework QuartzCore. framework CoreGraphics. framework-Xcode generally includes this framework file in the project by default.

To dynamically load library files to applications on the device in addition to the debugger, you need to add the code sign to the libReveal. dylib file during the build process.

Enter the targetBuild PhasesTab, selectEditor → Add Build Phase → Add Run ScriptMenu. Add the following content to the Run Script stage:

set -eif [ -n "${CODE_SIGN_IDENTITY}" ]; then    codesign -fs "${CODE_SIGN_IDENTITY}" "${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}/libReveal.dylib"fi

Add the following code to the appropriate class file in the project (for example, yourUIApplicationDelegate), Modify it to meet your needs:

Swift:

// MARK: - Revealfunc loadReveal() {    if NSClassFromString("IBARevealLoader") == nil {        let revealLibName = "libReveal" // or "libReveal-tvOS" for tvOS targets        let revealLibExtension = "dylib"        var error: String?        if let dylibPath = NSBundle.mainBundle().pathForResource(revealLibName, ofType: revealLibExtension) {            print("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 {            let alert = UIAlertController(title: "Reveal library could not be loaded",                                        message: "\(revealLibName).\(revealLibExtension) failed to load with error: \(error!)",                                 preferredStyle: .Alert)            alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))            UIApplication.sharedApplication().windows.first?.rootViewController?.presentViewController(alert, animated: true, completion: nil)        }    }}

Objective-C:

#pragma mark - Reveal- (void)loadReveal{    if (NSClassFromString(@"IBARevealLoader") == nil)    {        NSString *revealLibName = @"libReveal"; // or @"libReveal-tvOS" for tvOS targets        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];            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Reveal library could not be loaded"                                                                           message:message                                                                    preferredStyle:UIAlertControllerStyleAlert];            [alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]];            [[[[[UIApplication sharedApplication] windows] firstObject] rootViewController] presentViewController:alert animated:YES completion:nil];        }    }}

Warning do not call this method in release build to ensure that libReveal. dylib is loaded only in debug build of the application.

A simple integration method is-[UIApplicationDelegate applicationDidBecomeActive:]Call-(Void) loadRevealMethod To ensure that the Reveal library is loaded in as early as possible.
Swift:

1. func applicationDidBecomeActive:(application: UIApplication) { self.loadReveal()}

Objective-C:

(void)applicationDidBecomeActive:(UIApplication *)application{[self loadReveal];}

Prompt: In-[UIApplicationDelegate applicationDidBecomeActive:]The Reveal service is automatically started when the application is started.

If you do not want to automatically start the Reveal service as described in the preceding steps, you can also manually start the service, such as using a Debug button. After the application is started, call the loadReveal method and then dispatch an NSNotification named IBARevealRequestStart:
Swift:

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

Objective-C:

- (void)startReveal{    [[NSNotificationCenter defaultCenter] postNotificationName:@"IBARevealRequestStart" object:nil];}

Build and run your application in Xcode. If everything works properly, switch to the Reveal application. Your application will appear in the drop-down list of the application selector. Select your application to see the application interface running in the simulator (or device.

CocoaPods

CocoaPods is a dependency management system for iOS and OSX projects. It greatly simplifies the dependency management and configuration of third-party libraries in Xcode projects.

CocoaPods provides Podspec for integrating Reveal into your project.

Warning do not use applications connected to the Reveal library file for official release. The following guide describes how to use build configurations to make Reveal static library files accessible only during debugging build.

You must have configured CocoaPods In the project. If not, configure Cocoapods first.

Add the following content to your Podfile:

pod 'Reveal-iOS-SDK', :configurations => ['Debug']
Run the following command in the root directory of the project:Pod installCommand (if Cocoapods has been used in the project, runPod updateCommand ). Remove Reveal from your Xcode Project

Remove Reveal Based on the selected Reveal integration method.

Once the library file is successfully removed, the following content will no longer appear on the Xcode console when your application is started:

INFO: Reveal Server started (Protocol Version X ).

Open your Xcode project through static connections. SlaveProject NavigatorMediumDelete Reveal. framework. In XcodeProject NavigatorSelect your project. For each target integrated with Reveal, selectBuild SettingsTab.Linked FlagsRemove from settings:
-Framework Reveal-ObjC and-lz (make sure that this configuration is only used for Reveal before deletion ). -Run the application and confirm that Reveal is not connected to the application. Dynamic connection to open your Xcode project. From Project NavigatorDelete libReveal. dylib. Select your Project in Xcode Project Navigator. For each target integrated with Reveal, select the Build Phases tab. If the following library files are for Reveal only, remove them from Link Binary With Libraries Configuration:
Libz. dylib CFNetwork. framework QuartzCore. framework CoreGraphics. framework deletes the custom codesign content from the Run Script under Build Phases. SetloadReveal / startRevealMethods are deleted from your code. -Run the application and confirm that Reveal is not connected to the application. CocoaPods

Delete the following line in your Podfile file:

pod 'Reveal-iOS-SDK', :configurations => ['Debug']

Run the pod update command in the root directory of the project.

If your Podfile only has a pod dependency of Reveal-iOS-SDK, remove cococoapods from the project according to this description.

-Run the application and confirm that Reveal is not connected to the application.

Display Effect

Is the Reveal running interface, which is divided into three parts:

The left part is the hierarchical relationship of the entire interface. Here you can view the entire interface element in a tree-level layer.

The middle part is a visual view area. You can switch the 2D or 3D view mode here. What you see here is the real-time interface for running the program.

The right side is the detailed parameter view area of the Control. When a specific control is selected, a list of specific parameters of the control is displayed on the right side. In addition to checking whether these parameter values are correct, we can also try to modify these values. All modifications can be reflected to the real-time preview area in the middle.

ImportantDo not officially publish the application that has connected to the Reveal Library File. Reveal's inspection mechanism exposes a lot of internal information about your application, which may cause your application to be rejected by the Apple review team. Reveal is only used for internal development and application debugging.When the iOS app enters the background, the Reveal service will automatically stop. When the application is restarted, it is automatically started.Reveal supports apps compiled based on iOS 7 and later versions. The iOS Deployment Target in the build configuration must also be 'ios 7.0 'or an updated version. If the iOS version is too old, you may encounter a connection error during application building.Reveal uses the Bonjour protocol to connect runtime iOS applications. If your iOS app runs on a real device, the device also needs to be in the same network so that the Reveal app on the computer can connect to it. If you still encounter problems when connecting to the application, first check the firewall and proxy settings to ensure that they do not impede communication. Use Reveal to debug other application interfaces

If your device is jailbroken, you can use Reveal to "debug" other application interfaces. When will this strange requirement occur? -- When we want to learn how others implement the interface effect. IOS device directory/Library/MobileSubstrate/DynamicLibrariesAll the dynamic link libraries that need to be loaded when the system starts, so we only need to upload the Reveal dynamic link library to this directory.

For jailbreaking devices, we can use scp to upload the file after OpenSSH is installed. The procedure is as follows:

Upload libReveal. dylib to/Library/MobileSubstrate/DynamicLibraries
If libReveal. dylib does not have the execution permission, run the chmod + x libReveal. dylib command to grant it the execution permission.
Run killall SpringBoard to restart the desktop.

Related Article

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.