'Code module
#Region Project Attributes
#ApplicationLabel: Bluetooth SPP
#Version: 1.0.0
'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
#iPhoneOrientations: Portrait, LandscapeLeft, LandscapeRight
#iPadOrientations: Portrait, LandscapeLeft, LandscapeRight, PortraitUpsideDown
#PlistExtra: <key>UISupportedExternalAccessoryProtocols</key><array><string>com.RovingNetworks.btdemo</string></array>
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Public App As Application
Public NavControl As NavigationController
Private Page1 As Page
Dim AStreams As AsyncStreams
End Sub
Private Sub Application_Start (Nav As NavigationController)
NavControl = Nav
Page1.Initialize("Page1")
Page1.Title = "Page 1"
Page1.RootPanel.Color = Colors.White
NavControl.ShowPage(Page1)
Page1.RootPanel.LoadLayout("main")
Dim NativeMe As NativeObject = Me
NativeMe.RunMethod("viewloaded:", Array (True))
End Sub
Private Sub Page1_Resize(Width As Int, Height As Int)
End Sub
Private Sub Application_Background
End Sub
Sub ButtonScan_Click
Dim NativeMe As NativeObject = Me
NativeMe.RunMethod("doScan:", Array (True))
End Sub
Sub ButtonConnect_Click
End Sub
#If ObjC
EAAccessoryManager *mgr;
EASession *session;
#import <ExternalAccessory/ExternalAccessory.h>
- (void)viewloaded: (bool) on{
mgr = [EAAccessoryManager sharedAccessoryManager];
}
- (void)doScan: (bool) on{
NSLog(@"Starting Scan");
NSOutputStream *os = session.outputStream;
if ([mgr.connectedAccessories count])
{
if (os.hasSpaceAvailable)
{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: @"Warning !!!"
message: @"Device are already connected"
delegate: nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil]; [alert show];
[alert show];
}
else
{
/*[self connectBT];*/
}
}
else
{
[mgr showBluetoothAccessoryPickerWithNameFilter:nil completion:^(NSError *error){ NSLog(@"%@", [error localizedDescription]);}];
}
}
#End If