Note: The code on this page is for tutorial purposes only. It shows how to call the SDK and is not production-ready: it leaves out error handling, threading and app lifecycle management. Review and adapt it before you use it in your app.
Overview
Sets up the object that receives the SDK's asynchronous notifications, using srfidSetDelegate and srfidSubsribeForEvents.
Details
The SDK supports a set of asynchronous notifications to inform the application about RFID reader related events (e.g. reception of tag data, starting of radio operation etc.) and connectivity related events (e.g. appearance of RFID reader). All supported callbacks are defined by srfidISdkApiDelegate Objective C protocol. In order to receive asynchronous notifications from the SDK the application shall perform the following steps.
Step 1: create an object that implements srfidISdkApiDelegate
The ViewController.h class
#import <UIKit/UIKit.h>
#import <ZebraRfidSdkFramework/ZebraRfidSdkFramework.h>
@interface ViewController : UIViewController<srfidISdkApiDelegate> {
}
@end
The Event ViewController.m class. The methods are empty stubs. The page of each feature that uses an event shows its implementation; a class can implement a method only once, so use that implementation in place of the stub.
#import "ViewController.h"
@implementation ViewController
- (void)srfidEventBatteryNotity:(int)readerID aBatteryEvent:(srfidBatteryEvent *)batteryEvent {
// Add implementation here.
}
- (void)srfidEventCommunicationSessionEstablished:(srfidReaderInfo *)activeReader {
NSLog(@"Reader Connected");
/* commands to the reader (software version, capabilities, ...) work only after the ASCII connection is established */
readerID = [activeReader getReaderID];
SRFID_RESULT ascii_result = [apiInstance srfidEstablishAsciiConnection:readerID];
NSLog(@"ASCII connection result: %d", ascii_result);
}
- (void)srfidEventCommunicationSessionTerminated:(int)readerID {
NSLog(@"Reader Disconnected");
}
- (void)srfidEventMultiProximityNotify:(int)readerID aTagData:(srfidTagData *)tagData {
// Add implementation here.
}
- (void)srfidEventProximityNotify:(int)readerID aProximityPercent:(int)proximityPercent {
// Add implementation here.
}
- (void)srfidEventReadNotify:(int)readerID aTagData:(srfidTagData *)tagData {
// Add implementation here.
}
- (void)srfidEventReaderAppeared:(srfidReaderInfo *)availableReader {
// Add implementation here.
}
- (void)srfidEventReaderDisappeared:(int)readerID {
// Add implementation here.
}
- (void)srfidEventStatusNotify:(int)readerID aEvent:(SRFID_EVENT_STATUS)event aNotification:(id)notificationData {
// Add implementation here.
}
- (void)srfidEventTriggerNotify:(int)readerID aTriggerEvent:(SRFID_TRIGGEREVENT)triggerEvent {
// Add implementation here.
}
- (void)srfidEventWifiScan:(int)readerID wlanSCanObject:(srfidWlanScanList *)wlanScanObject {
// Add implementation here.
}
- (void)srfidEventIOTSatusNotity:(int)readerID aIOTStatusEvent:(srfidIOTStatusEvent *)iotStatusEvent {
// Add implementation here.
}
- (void)srfidEventConnectedInterfaceNotity:(int)readerID aConnectedInterfaceEvent:(sfidConnectedInterfaceEvent *)connectedInterfaceEvent {
// Add implementation here.
}
@end
Step 2: register the created object as a notification receiver via srfidSetDelegate API function.
-(void)registerOfcallbackInterfaceWithSDK {
/* registration of callback interface with SDK */
[apiInstance srfidSetDelegate:self];
}
Step 3: subscribe for asynchronous event of particular types via srfidSubsribeForEvents API function.
If a particular object is registered as a notification receiver the SDK will call the corresponding method of the registered object when a particular event occurs if the application is subscribed for events of this type. The SDK may deliver asynchronous events on a main thread or on one of SDK helper threads so the object that implements srfidISdkApiDelegate protocol shall be thread-safe.
-(void)subcribeForEvent {
int notifications_mask_reader_connection = SRFID_EVENT_READER_APPEARANCE | SRFID_EVENT_READER_DISAPPEARANCE | SRFID_EVENT_SESSION_ESTABLISHMENT |
SRFID_EVENT_SESSION_TERMINATION;
[apiInstance srfidSubsribeForEvents:notifications_mask_reader_connection];
/* subscribe for battery and handheld trigger related events */
[apiInstance srfidSubsribeForEvents:(SRFID_EVENT_MASK_BATTERY | SRFID_EVENT_MASK_TRIGGER)];
[apiInstance srfidSubsribeForEvents:(SRFID_EVENT_MASK_READ | SRFID_EVENT_MASK_STATUS | SRFID_EVENT_MASK_STATUS_OPERENDSUMMARY)];
[apiInstance srfidSubsribeForEvents:(SRFID_EVENT_MASK_TEMPERATURE | SRFID_EVENT_MASK_POWER | SRFID_EVENT_MASK_DATABASE)];
[apiInstance srfidSubsribeForEvents:(SRFID_EVENT_MASK_PROXIMITY)];
[apiInstance srfidSubsribeForEvents:(SRFID_EVENT_MASK_MULTI_PROXIMITY)];
}
Next, open a session with a reader: see Connect.