iOS Question Create stream for connection made by native code

Discussion in 'iOS Questions' started by mrossen, Jan 23, 2015.

  1. mrossen

    mrossen Active Member Licensed User


    Is it possible to use:

    AStreams.InitializePrefix(Serial1.InputStream, True, Serial1.OutputStream, "AStreams")
    to get the stream created with inline code.

    I cannot use Serial1. because I don't have it.

    I can make the SSP connection with the inline code and want to grab the stream in b4i code, then I can reuse my B4A code :)

    Can this be done?

    Can I make a event to see when the connection done ?

  2. Erel

    Erel Administrator Staff Member Licensed User

    Which type of object does your inline code return?
  3. mrossen

    mrossen Active Member Licensed User


    I can figure that out.

    I atttached my demo project


    Attached Files:

  4. Erel

    Erel Administrator Staff Member Licensed User

    Create a method that returns NSOutputStream* and return session.outputstream. It will be converted to B4i OutputStream object which you can use with AsyncStreams (start in non-prefix mode).
  5. mrossen

    mrossen Active Member Licensed User

    Thank you for your reply,

    I can see what you mean but I can not figure out how to do it.

    I have made a new test project where I only connect to the bluetooth module.

    The file is attached

    When I get this connection can I here get the stream.

    This is only for the output. I also need to have a stream for the input, right?

    I am realy lost so if anyone have a solution or hints anythink may be usefull

    '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.Title = 
    "Page 1"
        Page1.RootPanel.Color = 
    Dim NativeMe As NativeObject = Me
    "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
    "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
                                      otherButtonTitles:nil]; [alert show];

                [alert show];

            /*[self connectBT];*/

            [mgr showBluetoothAccessoryPickerWithNameFilter:nil completion:^(NSError *error){ NSLog(@"%@", [error localizedDescription]);}];


    #End If

    Attached Files:

    vincentehsu likes this.
  6. Alberto Iglesias

    Alberto Iglesias Well-Known Member Licensed User

    Hello mrossen, do you finish this example? bluetooth_spp connecting with protocol and work?

    Can you send to me?

    I´m developing now a Library and App to connect with external device with MFi and need to try everything.


    Alberto Iglesias
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice