YYDebugDatabase 2.1.1

YYDebugDatabase 2.1.1

测试已测试
语言语言 Obj-CObjective C
许可证 NOASSERTION
发布最新发布2022年3月

y500 维护。



 
依赖
GCDWebServer>= 0
FMDB>= 0
 

  • y500

YYDebugDatabase

YYDebugDatabase 是一个强大的库,用于调试 iOS 应用程序中的数据库,类似于 Android 的调试数据库。

YYDebugDatabase 允许您以非常简单的方式直接在浏览器中查看和编辑数据库。

YYDebugDatabase 能做什么?

  • 查看所有数据库。
  • 在指定的数据库上运行任何 SQL 查询以更新和删除您的数据。
  • 直接编辑数据库值。
  • 直接在数据库中添加一行。
  • 删除数据库行。
  • 搜索数据。
  • 排序数据。
  • 下载数据库。

版本 2.0.0:

  • 将 CocoaAsyncSocket 替换为 GCDWebServer,这是一个更高级、更便捷的服务器。
  • 兼容 Firefox、Safari、Chrome。
  • 使用 bonjourname 作为服务器地址,例如:http://y500.localhttp://macbook.local:9002...
  • 在控制台打印服务器的链接地址和 bonjour 名称

安装

Podfile

要使用 CocoaPods 将 YYDebugDatabase 集成到您的 Xcode 项目中,请在您的 Podfile 中指定它

pod 'YYDebugDatabase'

如果使用 Swift,请记住添加 use_frameworks!

use_frameworks!
pod 'YYDebugDatabase'

Carthage

  • Cartfile
github "y500/iOSDebugDatabase"
  • 运行 carthage update

  • 将所有三个 .frameworks 添加到您的目标的“Embedd Frameworks”构建阶段

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

在发布版本中不构建

首先,在 Podfile 中添加配置。

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

然后,运行以下命令

$ pod install

使用方法

在 [](AppDelegate.m) 中导入

#import DebugDatabaseManager.h

application:didFinishLaunchingWithOptions 中添加一行代码

[[DebugDatabaseManager shared] startServerOnPort:9002];

在生产环境下不执行

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

如果使用 Swift

在 [](Appdelegate.swift) 中导入

import YYDebugDatabase

application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) 中添加一行代码

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

高级功能

默认情况下,它仅显示 Documents 目录和 Library/Cache 目录中的数据库,如果您想显示其他目录中的数据库,可以使用

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

例如

    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]];

如果使用 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]);

以上即是所有内容(您可以通过查看演示了解详细信息),只需启动应用即可

现在请在浏览器中打开提供的链接,您将看到如下内容

查询

编辑

删除

重要

  • 您的 iPhone 和笔记本电脑应该连接到同一个网络(Wi-Fi 或 LAN)。
  • 链接地址的主机是 iPhone 的网络地址。
  • 如果您使用的是模拟器,可以使用以下地址:[http://127.0.0.1:9002](http://127.0.0.1:9002)。
  • 端口号必须与您在 AppDelegate.m 中写入的相同

### 其他更多

您可以在控制台像以下这样找到地址和Bonjour地址:

[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/

许可

   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

       https://apache.ac.cn/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.