Friday, September 9, 2022

How to get a list of paired bluetooth devices (Mac OS)

 https://gist.github.com/jamesmartin/9847466aba513de9a77507b56e712296

import IOBluetooth
// See https://developer.apple.com/reference/iobluetooth/iobluetoothdevice
// for API details.
class BluetoothDevices {
func pairedDevices() {
print("Bluetooth devices:")
guard let devices = IOBluetoothDevice.pairedDevices() else {
print("No devices")
return
}
for item in devices {
if let device = item as? IOBluetoothDevice {
print("Name: \(device.name)")
print("Paired?: \(device.isPaired())")
print("Connected?: \(device.isConnected())")
}
}
}
}
var bt = BluetoothDevices()
bt.pairedDevices()

How to get access to Bluetooth on Mac OS

 using RFICOMM and iAP2

https://developer.apple.com/documentation/iobluetooth/iobluetoothdevice


Wednesday, September 7, 2022

How to register and use MFi

Apple MFi FAQ:

https://mfi.apple.com/en/faqs.html


View who does not need to join the MFi Program.
  • Developers and manufacturers of non-electronic accessories, including non-MagSafe cases and Apple Watch bands. Get guidelines and resources for designing accessories that do not incorporate MFi licensed technologies.
  • Distributors and resellers that want to source or sell MFi accessories as finished goods. MFi finished goods must be sourced from an authorized MFi manufacturer. The MFi Licensee will be authorized to develop/manufacture goods sold under your company's brand and will take responsibility for all program requirements on your company's behalf. The Licensee will also be authorized to include the correct MFi badge on the product packaging and user guide of your accessory, once it has completed the necessary program requirements.
  • Developers and manufacturers of accessories that connect to an Apple device using only Bluetooth Low Energy, Core Bluetooth, or standard Bluetooth profiles supported by iOS. Learn more about Bluetooth(Note: BLE-enabled HomeKit accessories and BLE-enabled MFi Hearing Aids are part of the MFi Program).
  • Educational organizations that want to use the MFi technical specifications for teaching purposes. The information shared under the MFi Program is Apple Confidential and is not intended to be used in an academic setting.
  • Hobbyists and makers creating smart home accessories can use the non-commercial version of the HomeKit Accessory Protocol Specification.
  • Individuals creating accessories for personal use. We recommend using a third-party hobbyist solution to connect iOS devices to serial devices, and to write apps that communicate with these serial devices.
  • App developers creating apps that communicate with MFi accessories. App developers should join the Apple Developer Program. However, it is up to the accessory developer or manufacturer to determine whether they wish to authorize specific third-party apps to communicate with their MFi accessories through the External Accessory Framework. App developers should consult with the accessory developer to determine whether to proceed with development of an app that communicates with an MFi accessory using the EA framework.

Steps to follow for App developer and Device developer:
https://usermanual.wiki/Pdf/Guide20to20Submitting20Apps20that20Work20with20Accessories20R2.781218596/help


Some Apple forum discussion:

https://developer.apple.com/forums/thread/4905



Tuesday, September 6, 2022

Tuesday, March 15, 2022

NSPredicate example and how to use them

 https://academy.realm.io/posts/nspredicate-cheatsheet/

Format string summary

@"attributeName == %@"

object’s attributeName value is equal to value passed in

@"%K == %@"

pass a string variable to %K, it will be represented as a keypath, then check if it’s value is equal to value passed in

@"%name IN $NAME_LIST"

templated for predicate, checks if the value of key name is in $NAME_LIST. Uses predicateWithSubstitutionVariables

@"'name' IN $NAME_LIST"

checks if the constant value ‘name’ is in $NAME_LIST. Uses predicateWithSubstitutionVariables

[NSPredicate predicateWithFormat: @"title == %@", @"minecraft"]


Tuesday, February 22, 2022

Explain how runloops work

 https://khorbushko.github.io/article/2020/11/29/runloop-in-depth.html


RunLoop is the implementation of well-known EventLoop pattern - * programming construct or design pattern that waits for and dispatches events or messages in a program*.

while (!end) { } 

This pattern has been implemented on many platforms. Thus, the main problems that it should resolve are:

  • receive events/messages
  • work when works exist and sleep when no work available (correct resource management).

Hight level description of Thread:

thread life

Hight level description of EventLoop:

thread life

iOS/macOS RunLoop

Talking about iOS/macOS we always refer to RunLoop. To be more correct - 2 classes implement this behavior:

  • CFRunLoopRef (open source)
  • NSRunLoop (based on CFRunLoopRef)

As you already see, RunLoop is connected to the thread. You can’t create RunLoop directly, instead, it’s can be created at the very start of Thread creating and destroyed at the very end of theThread lifecycle. There are 2 function that provide access to RunLoop - CFRunLoopGetMain()and CFRunLoopGetCurrent()

debug backtrace

Run loops are part of the fundamental infrastructure associated with threads. A run loop is an event processing loop that you use to schedule work and coordinate the receipt of incoming events. The purpose of a run loop is to keep your thread busy when there is work to do and put your thread to sleep when there is none. - Apple.