Develop via Xcode
You can develop iOS applications to use Brother Print SDK via Xcode.
Add the SDK
- Put
BT_Net/BRLMPrinterKit.xcframeworkorNet/BRLMPrinterKit.xcframeworkat any location - Add it to Embedded Binaries and Linked Frameworks and Libraries of your application target
- Add Framework Search Paths and Header Search Paths if needed
BT_Net/BRLMPrinterKit.xcframework is required when your application print via Bluetooth using MFi compatible printers, otherwise you can use Net/BRLMPrinterKit.xcframework.
The following information is required in Info.plist when your application use Bluetooth.
- Add
UISupportedExternalAccessoryProtocolskey (Supported external accessory protocols) toInfo.plistif not exists - Add an item
com.brother.ptcbpto the key
The following information is required when building an app that uses a network printer with Xcode 12 or later.
- Add
NSLocalNetworkUsageDescription(Privacy - Local Network Usage Description) andNSBonjourServices(Bonjour services) inInfo.plist. - Set the text value required in your app in
NSLocalNetworkUsageDescription. - Set the following values in
NSBonjourServices:_pdl-datastream._tcp_printer._tcp_ipp._tcp
Check Apple's developer site for OS and development environment updates.
Implement Feature using the SDK
Follows is minimum code to connect to the printer. See each guides for more details.
Swift
import BRLMPrinterKit func yourGreatFeature() { let channel = BRLMChannel(wifiIPAddress: "IPAddress.of.your.printer") let generateResult = BRLMPrinterDriverGenerator.open(channel) guard generateResult.error.code == BRLMOpenChannelErrorCode.noError, let printerDriver = generateResult.driver else { print("Error - Open Channel: %d", generateResult.error.code) return } print("Success - Open Channel") // // Put any code to use printer // printerDriver.closeChannel() }
Objective-C
#import <BRLMPrinterKit.h> - (void)yourGreatFeature { BRLMChannel *channel = [[BRLMChannel alloc] initWithWifiIPAddress:@"IPAddress.of.your.printer"]; BRLMPrinterDriverGenerateResult *generateResult = [BRLMPrinterDriverGenerator openChannel:channel]; if (generateResult.error.code != BRLMOpenChannelErrorCodeNoError || generateResult.driver == nil) { NSLog(@"Error - Open Channel: %@", @(generateResult.error.code)); return; } NSLog(@"Success - Open Channel"); BRLMPrinterDriver *printerDriver = generateResult.driver; // // Put any code to use printer // [printerDriver closeChannel]; }
Get Product Plan ID
You have to have Product Plan ID (PPID) in order to submit the application for MFi compatible printers to App Store. PPID will be informed to you from Brother Industries, Ltd. Please proceed this instructions. You don't have to proceed it if you do not distribute your application from App Store.
Notes when using Bluetooth connection
When your app uses Bluetooth connection, iOS requests the permission from users.
To do that, the purpose of using Bluetooth needs to be added into Info.plist.
Add the following key to Info.plist in your app. (The following value of type string is an example.)
<key>NSBluetoothAlwaysUsageDescription</key> <string>Used to connect to your printer</string>
If your app's deployment target is earlier than iOS 13, following key needs also to be added into Info.plist in your app.
(The following value of type string is an example.)
<key>NSBluetoothPeripheralUsageDescription</key> <string>Used to connect to your printer</string>
Notes when releasing to the App Store
When you submit your App including BRLMPrinterKit.framework ,version 4.3.1 or lower, to App Store,
you have to delete simulator architectures (i386, x86_64) by running following commands.
$ cp -v [your current directory]/BRLMPrinterKit.framework/BRLMPrinterKit [your backup directory]/BRLMPrinterKit.framework/BRLMPrinterKit $ lipo -remove i386 [your current directory]/BRLMPrinterKit.framework/BRLMPrinterKit -o [your current directory]/BRLMPrinterKit.framework/BRLMPrinterKit $ lipo -remove x86_64 [your current directory]/BRLMPrinterKit.framework/BRLMPrinterKit -o [your current directory]/BRLMPrinterKit.framework/BRLMPrinterKit
You can check if the simulator architectures (i386, x86_64) are deleted from BRLMPrinterKit.framework by running following commands.
$ lipo -info [your current directory]/BRLMPrinterKit.framework/BRLMPrinterKit
Tips to resolve build errors with Xcode 12
When you get one of two errors below with Xcode 12 or later and BRLMPrinterKit.framework ,version 4.3.1 or lower, the followings may resolve the error.
1)"Building for iOS, but the linked and embedded framework 'BRLMPrinterKit.framework' was built for iOS + iOS Simulator."
To fix this error, you must once set Validate Workspace setting Yes and build. After that, you can specify either Yes or No, but the build result will be slightly different.
Yes: This will produce a warning instead of the error, but you can build your app.No: This will not produce a warning or error, and you can build your app.
2)"Building for iOS Simulator, but linking in dylib built for iOS"
Exclude arm64 for simulator architecture from your project. To do that, navigate to Build Settings of your project and add Any iOS Simulator SDK with value arm64 inside Excluded Architecture.