コンテンツにスキップ
QISHU DOCUMENT ARCHIVE

啓枢アーカイブ

製品ドキュメント、インターフェース資料、エンジニアリング記録の入口です。

sdk / objective-c

Objective-C SDK

iOS Objective-C プロジェクト向けの NIB プリンター SDK 導入説明。

Objective-C SDK は、既存の iOS プロジェクト、Objective-C / Swift 混在プロジェクト、framework または Nib.xcframework 形式で配布されるプロジェクトに適しています。標準の入口ヘッダーは次のとおりです。

#import <Nib/Nib.h>
モジュール よく使う型
Core BNDeviceBNScriptBNWritePipelineBNReceiveSourceBNQueryDispatcher
BLE BNBleCentralBNBleDeviceBNBleConnectionOptions、credit フロー制御。
Boxliy dialects BNEscBoxliyBNTsplBoxliyBNCpclBoxliy とレスポンス parser。
Aryten dialects BNEscArytenBNTsplArytenBNCpclAryten
Lin8inch dialects BNEscLin8inchBNTsplLin8inch
Image helpers 配布パッケージで利用可能な画像準備と印刷補助機能。

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;
@end

BNScript は構築済みの NSData を保持し、BNWritePipelinechunkSize に従って 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 のレシート形式出力を使う場合は、BNEscBoxliyBNScript を構築することもできます。どの方言を使う場合でも、実際の書き込みは BNDevice または BNWritePipeline に任せます。

BLE の入口は BNBleCentral です。よくある流れは次のとおりです。

  1. BNBleCentral を作成します。
  2. startDiscoveryWithDisconnectConnectedDevice:useMac:timeout:serviceUUIDs:discovered:error: を呼び出してスキャンします。
  3. BNBleDiscoveredDevice を選びます。
  4. BNBleConnectionOptions を作成し、デバイスに合わせて service、write、read、write mode、credit を設定します。
  5. connectDiscoveredDevice:options:completion: を呼び出して BNBleDevice を取得します。
  6. 方言ビルダーでスクリプトを生成します。
  7. BNWritePipeline または BNBleDevice で書き込みます。

BNBleConnectionOptions では writeMode を設定できます。これは BNBleWriteMode の with response / without response 書き込みモードに対応します。

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 を設定します。

Core の受信とクエリの型には、BNReceiveSourceBNCallbackReceiveSourceBNPollingReceiveSourceBNReceiveListenerBNQueryDispatcherBNPendingQueryBNResponseMatcher があります。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

ObjectMethod / CommandPurposeParameters
BNDevice / BNScriptwriteData:error:, readWithTimeout:error:, closeWithError:, data, hexString, base64String, stringValue, lengthAbstracts the real printer connection for templates, write pipelines, and query handling.Objective-C reports failures through NSError pointers; BNScript stores NSData.
BNWritePipeline / BNPeninitWithDevice:chunkSize:, writeData:error:, writeScript:error:, appendByte:, appendBytes:length:, appendData:, appendText:, appendCRLF, clear, resetWrites built bytes to a device with chunking, timeout, cancellation, and flow-control rules.`chunkSize` controls chunking; BNPen manually appends bytes and text.
BNBleCentral / BNBleDevicestartDiscoveryWithDisconnectConnectedDevice: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 / BNQueryDispatcherstartWithListener:, stop, acceptData:, queryWithMatcher:timeout:, cancelQuery:error:, shutdownRoutes 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

ObjectMethod / CommandPurposeParameters
BNEscBoxliy / BNEscArytenreset, 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:, clearBuilds ESC/Boxliy commands for receipt, portable, and ESC-compatible printers.Parameters follow Objective-C selectors; images take NSData, byteWidth, height, or PXPreparedBitmap.
BNTsplBoxliy / BNTsplArytensizeWithWidth: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:, clearBuilds 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 / BNCpclArytenbeginWithHeight: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:, clearBuilds 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 / BNTsplLin8inchbatteryLevel, extendedModel, bootVersion, advancedDensity:, mediaProfile:, wirelessProvisioningWithSSID:password:mode:, compressedRasterTransport, automaticStatusFeedback:, printCompletionD1:d2:d3:d4:, printerStatus:, configureStock:markOrGapMm:offsetMm:, configurePresentation:, twoColorRibbon:, directThermalLin8inch 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

ObjectMethod / CommandPurposeParameters
BNEscResponseParser / BNTsplResponseParser / BNCpclResponseParserparseData:, 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.
  • 実機で Bluetooth 権限、前後景切り替え、切断後の再接続、連続印刷を検証してください。
  • 大きな画像とラベルテンプレートは、どちらも BNWritePipeline で分割書き込みしてください。
  • UUID、write mode、credit 戦略は、具体的な機種に合わせて確認する必要があります。
  • Objective-C と Swift の混在時は、テンプレート層を通常の SDK 型のまま保ち、ページライフサイクルへ直接依存しないようにしてください。