啓枢アーカイブ
製品ドキュメント、インターフェース資料、エンジニアリング記録の入口です。
Objective-C SDK
iOS Objective-C プロジェクト向けの NIB プリンター SDK 導入説明。
Objective-C SDK は、既存の iOS プロジェクト、Objective-C / Swift 混在プロジェクト、framework または Nib.xcframework 形式で配布されるプロジェクトに適しています。標準の入口ヘッダーは次のとおりです。
#import <Nib/Nib.h>Framework 内容
Section titled “Framework 内容”| モジュール | よく使う型 |
|---|---|
| Core | BNDevice、BNScript、BNWritePipeline、BNReceiveSource、BNQueryDispatcher。 |
| BLE | BNBleCentral、BNBleDevice、BNBleConnectionOptions、credit フロー制御。 |
| Boxliy dialects | BNEscBoxliy、BNTsplBoxliy、BNCpclBoxliy とレスポンス parser。 |
| Aryten dialects | BNEscAryten、BNTsplAryten、BNCpclAryten。 |
| Lin8inch dialects | BNEscLin8inch、BNTsplLin8inch。 |
| Image helpers | 配布パッケージで利用可能な画像準備と印刷補助機能。 |
Core オブジェクト
Section titled “Core オブジェクト”BNDevice は最小デバイス契約です。
@protocol BNDevice <NSObject>
@property(nonatomic, copy, readonly) NSString *name;@property(nonatomic, assign, readonly) BOOL connected;
- (BOOL)writeData:(NSData *)data error:(NSError **)error;- (NSData *)readWithTimeout:(NSTimeInterval)timeout error:(NSError **)error;- (BOOL)closeWithError:(NSError **)error;
@endBNScript は構築済みの NSData を保持し、BNWritePipeline は chunkSize に従って BNDevice へ分割書き込みします。
#import <Nib/Nib.h>
id<BNDevice> connectedDevice = /* BLE 或平台设备 */;
BNTsplAryten *printer = [[BNTsplAryten alloc] init];BNScript *script = [[[[[printer sizeWithWidth:40 height:30] cls] textAtX:20 y:20 content:@"NIB SDK"] print] script];
BNWritePipeline *pipeline = [[BNWritePipeline alloc] initWithDevice:connectedDevice chunkSize:512];
NSError *error = nil;BOOL ok = [pipeline writeScript:script error:&error];デバイスが ESC のレシート形式出力を使う場合は、BNEscBoxliy で BNScript を構築することもできます。どの方言を使う場合でも、実際の書き込みは BNDevice または BNWritePipeline に任せます。
BLE 導入
Section titled “BLE 導入”BLE の入口は BNBleCentral です。よくある流れは次のとおりです。
BNBleCentralを作成します。startDiscoveryWithDisconnectConnectedDevice:useMac:timeout:serviceUUIDs:discovered:error:を呼び出してスキャンします。BNBleDiscoveredDeviceを選びます。BNBleConnectionOptionsを作成し、デバイスに合わせて service、write、read、write mode、credit を設定します。connectDiscoveredDevice:options:completion:を呼び出してBNBleDeviceを取得します。- 方言ビルダーでスクリプトを生成します。
BNWritePipelineまたはBNBleDeviceで書き込みます。
BNBleConnectionOptions では writeMode を設定できます。これは BNBleWriteMode の with response / without response 書き込みモードに対応します。
BLE credit フロー制御
Section titled “BLE credit フロー制御”credit API は BNBleCredit.h にあります。
| API | 用途 |
|---|---|
BNBleCreditOptions |
credit の有効化、UUID、初期 credit、MTU、戦略、fallback を設定します。 |
BNBleLaneCreditWriter |
lane-credit writer。 |
BNBleSignalCreditWriter |
signal-credit writer。 |
BNBleFlowControlStrategy |
カスタムフロー制御戦略プロトコル。 |
[BNBleCreditOptions defaultOptions] は FF00 service、FF02 write、FF01 read、FF03 credit notify を使い、初期 credit は 1、初期 MTU は 20、payload overhead は 3 です。通常の BNBleConnectionOptions はデフォルトで credit を有効にしません。デバイスが credit 通知を必要とする場合だけ creditOptions を設定します。
受信、クエリ、解析
Section titled “受信、クエリ、解析”Core の受信とクエリの型には、BNReceiveSource、BNCallbackReceiveSource、BNPollingReceiveSource、BNReceiveListener、BNQueryDispatcher、BNPendingQuery、BNResponseMatcher があります。BLE デバイスも receiveSource を公開しており、通知応答に利用できます。
Boxliy 方言 parser 名は次のとおりです。
| 方言 | parser |
|---|---|
| ESC | BNEscResponseParser |
| TSPL | BNTsplResponseParser |
| CPCL | BNCpclResponseParser |
「クエリ命令を送信し、応答を待ち、parser を呼び出す」処理は印刷セッション層に担当させ、UI 層は結果表示だけを行うことをおすすめします。
Methods and Commands
The tables below list the public entry points integration teams usually need. Builder methods generate printer commands; actual availability still depends on the ESC, TSPL, CPCL, or Lin8inch command family supported by the target firmware.
Core, Connection, and Writing
| Object | Method / Command | Purpose | Parameters |
|---|---|---|---|
BNDevice / BNScript | writeData:error:, readWithTimeout:error:, closeWithError:, data, hexString, base64String, stringValue, length | Abstracts the real printer connection for templates, write pipelines, and query handling. | Objective-C reports failures through NSError pointers; BNScript stores NSData. |
BNWritePipeline / BNPen | initWithDevice:chunkSize:, writeData:error:, writeScript:error:, appendByte:, appendBytes:length:, appendData:, appendText:, appendCRLF, clear, reset | Writes built bytes to a device with chunking, timeout, cancellation, and flow-control rules. | `chunkSize` controls chunking; BNPen manually appends bytes and text. |
BNBleCentral / BNBleDevice | startDiscoveryWithDisconnectConnectedDevice:timeout:handler:, stopDiscovery, connectDiscoveredDevice:options:completion:, disconnectCurrentDevice, writeData:error:, readWithTimeout:error: | Handles BLE characteristic selection, MTU chunking, credit notifications, and fallback writes. | `BNBleConnectionOptions` configures UUIDs, timeouts, writeMode, credit, and flowControl. |
BNReceiveSource / BNQueryDispatcher | startWithListener:, stop, acceptData:, queryWithMatcher:timeout:, cancelQuery:error:, shutdown | Routes device responses into listeners or query dispatchers for status, battery, model, and similar queries. | The matcher block returns a result from NSData; listeners receive data/error/closed events. |
Command Builders
| Object | Method / Command | Purpose | Parameters |
|---|---|---|---|
BNEscBoxliy / BNEscAryten | reset, text:, newLine, bold:, underline:, fontWidth:height:, lineRow:, feed:, lineDot:, backLineDot:, location:, cut, lineDotCut, batteryVolume, info, model, version, printerVersion, name, mac, sn, state, status, enable, stopJob, wakeup, wakeupWithLength:, barcodeValue:type:height:, qrcodeValue:size:level:, imageData:byteWidth:height:, imagePreparedBitmap:, rawData:, clear | Builds ESC/Boxliy commands for receipt, portable, and ESC-compatible printers. | Parameters follow Objective-C selectors; images take NSData, byteWidth, height, or PXPreparedBitmap. |
BNTsplBoxliy / BNTsplAryten | sizeWithWidth:height:, cls, print, printWithCopies:, density:, speed:, direction:mirror:, gap:, gapWithHeight:offset:, blineWithHeight:offset:, continuous, labelWithHeight:offset:, offset:, ribbon:, shift:, referenceWithHorizontal:vertical:, cut:, tear:, peel:, status, state, batteryVolume, version, versions, model, models, sn, sns, textAtX:y:content:, textAtX:y:font:rotation:xMulti:yMulti:content:, barcodeAtX:y:value:, qrcodeAtX:y:value:cellWidth:level:version:, bitmapAtX:y:data:byteWidth:height:, raw:, rawData:, clear | Builds TSPL label commands for templates with paper size, coordinates, barcodes, and QR codes. | Paper uses width/height/gap/offset; elements use x/y; QR uses cellWidth, level, and version. |
BNCpclBoxliy / BNCpclAryten | beginWithHeight:copies:, pageWidth:, textWithFont:size:x:y:content:, barcodeAtX:y:value:, barcodeType:width:ratio:height:x:y:value:rotation:, qrcodeAtX:y:value:cellWidth:level:, lineFromX:y:toX:y:thickness:dashed:, boxFromX:y:toX:y:thickness:, imageAtX:y:data:byteWidth:height:, bold:, underline:, waterMark:, gapSense, form, print, status, sn, model, version, batteryVolume, raw:, rawData:, clear | Builds CPCL label commands for page setup, text, lines, barcodes, and images. | CPCL selectors carry parameter meaning in their names; coordinate, size, and thickness units depend on model DPI. |
BNEscLin8inch / BNTsplLin8inch | batteryLevel, extendedModel, bootVersion, advancedDensity:, mediaProfile:, wirelessProvisioningWithSSID:password:mode:, compressedRasterTransport, automaticStatusFeedback:, printCompletionD1:d2:d3:d4:, printerStatus:, configureStock:markOrGapMm:offsetMm:, configurePresentation:, twoColorRibbon:, directThermal | Lin8inch extension methods across ESC and TSPL command families. | Provisioning takes SSID/password/mode; status feedback takes a flag or token; media configuration takes sensor, mark/gap, and offset. |
Response Parsing
| Object | Method / Command | Purpose | Parameters |
|---|---|---|---|
BNEscResponseParser / BNTsplResponseParser / BNCpclResponseParser | parseData:, parseQuery:data:, hexStringForData: | Parses printer responses into status, battery, text, MAC, event, or unknown response objects. | Response objects include query, type, rawData, rawHex, statusByte, statusFlags, isReady, batteryLevel, text, macAddress, and description. |
実践上のおすすめ
Section titled “実践上のおすすめ”- 実機で Bluetooth 権限、前後景切り替え、切断後の再接続、連続印刷を検証してください。
- 大きな画像とラベルテンプレートは、どちらも
BNWritePipelineで分割書き込みしてください。 - UUID、write mode、credit 戦略は、具体的な機種に合わせて確認する必要があります。
- Objective-C と Swift の混在時は、テンプレート層を通常の SDK 型のまま保ち、ページライフサイクルへ直接依存しないようにしてください。