Skip to content

make it easy to debug databases in iOS applications iOS debug database

License

Notifications You must be signed in to change notification settings

y500/iOSDebugDatabase

Repository files navigation

YYDebugDatabase

YYDebugDatabase is a powerful library for debugging databases in iOS applications. Which like Android Debug database

YYDebugDatabase allows you to view and edit databases directly in your browser in a very simple way.

What can YYDebugDatabase do?

  • See all the databases.
  • Run any sql query on the given database to update and delete your data.
  • Directly edit the database values.
  • Directly add a row in the database.
  • Delete database rows.
  • Search in your data.
  • Sort data.
  • Download database.

Release 2.0.0:

  • Replace CocoaAsyncSocket with GCDWebServer, which is higher level server that more convenient.
  • Satisfy with Firefox, Safari, Chrome.
  • Use bonjourname as the server address, for example: http://y500.local, http://macbook.local:9002...
  • print link address and bonjour name of the server in the console

Installation

Podfile

To integrate YYDebugDatabase into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'YYDebugDatabase'

If use Swift, remember to add use_frameworks!

use_frameworks!
pod 'YYDebugDatabase'

Carthage

  • Cartfile
github "y500/iOSDebugDatabase"
  • run carthage update

  • Add all three .frameworks to your target "Embedd Frameworks" Build Phase:

    • iOSDebugDatabase.framework
    • FMDB.framework
    • GCDWebServers.framework

Not build in Release

First, add configurations in Podfile.

pod 'YYDebugDatabase', :configurations => ['Debug']

Then, run the following command:

$ pod install

USage

import at AppDelegate.m:

#import DebugDatabaseManager.h

making one line code at application:didFinishLaunchingWithOptions:

[[DebugDatabaseManager shared] startServerOnPort:9002];

Not run in Release

#ifdef DEBUG
	[[DebugDatabaseManager shared] startServerOnPort:9002];
#end

If use Swift:

import at Appdelegate.swift:

import YYDebugDatabase

making one line code at application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?):

DebugDatabaseManager.shared().startServer(onPort: 9002);

Advanced

It only shows the databasesin in Documents directory and Library/Cache directory by default, if you want show databases in other directories, you can use:

- (void)startServerOnPort:(NSInteger)port directories:(NSArray*)directories

for example:

    NSString *resourceDirectory = [[NSBundle mainBundle] resourcePath];
    NSString *databaseDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/database"];
    NSString *documentDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
    NSString *cacheDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Cache"];
    [[DebugDatabaseManager shared] startServerOnPort:9002 directories:@[resourceDirectory, databaseDirectory, documentDirectory, cacheDirectory]];

If use Swift:

    let directory:String = (Bundle.main.resourcePath)!;
    let documentsPath:String = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
    let cachePath:String = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true)[0]
    DebugDatabaseManager.shared().startServer(onPort: 9002, directories: [directory, documentsPath, cachePath]);

That’s all(you can look at the Demo for details), just start the application :

Now open the provided link in your browser, and you will see like this:

query:

edit:

delete:

Important:

  • Your iPhone and laptop should be connected to the same Network (Wifi or LAN).
  • the host of you link address is the iPhone's net address.
  • If you use Simulator you can use address: http://127.0.0.1:9002.
  • the port must be same as you write in Appdelegate.m

###other more:

you can find the address and bojourname address in the console like below:

[INFO] DebugDatabaseManager started on port 9002 and reachable at http://192.168.0.67:9002/
[INFO] DebugDatabaseManager now locally reachable at http://y500.local:9002/

License

   Copyright (C) 2016 y500

   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.