Skip to content
Titanium SDK
Titanium Docs
Version13.4.1

Titanium.Network.BonjourBrowser

proxyiPhoneiPadmacOSsince 1.2.0

Extends Titanium.Proxy

A browser for the discovery and retrieval of Bonjour services available on the network.

Use the Titanium.Network.createBonjourBrowser method to create a BonjourBrowser instance.

If your application publishes Bonjour services itself, that service will be discovered by the browser if necessary; be prepared to perform a check if you do not want to list local services as available. Bonjour service browsing is an asynchronous operation, meaning that you should be extremely careful when caching values from the services property returned by the updatedservices event. In particular, if you maintain a local copy of available services and a user tries to connect to one, you should be prepared to handle failures gracefully; the next updatedservices event should provide the new services list, but you should not rely on it being delivered before user input. When a window which uses Bonjour browsing is closed, if you do not want to continue searching, you must call the stop() method.

In iOS 14.0+, to browse services add key NSLocalNetworkUsageDescription and NSBonjourServices to the ios plist section of the tiapp.xml file.

Example:

<ti:app>
  <!-- ... -->
  <ios>
    <plist>
      <dict>
        <!-- Reason to access local network-->
        <key>NSLocalNetworkUsageDescription</key>
        [string](api:Global.String)
            Specify the reason for accessing the local network.
            This appears in the alert dialog when asking the user 
            for permission to access local network.
        </string>
        <!-- List of bonjour service type-->
        <key>NSBonjourServices</key>
        <array>
          [string](api:Global.String)_test._tcp</string>
        <array/>
      </dict>
    </plist>
  </ios>
  <!-- ... -->
</ti:app>

Properties 5

apiName

Stringsince Android 3.2.0, iPhone 3.2.0, iPad 3.2.0, macOS 9.2.0read-only

Inherited from Titanium.Proxy

The name of the API that this proxy corresponds to.

bubbleParent

Booleansince Android 3.0.0, iPhone 3.0.0, iPad 3.0.0, macOS 9.2.0

Inherited from Titanium.Proxy

Indicates if the proxy will bubble an event to its parent.

Default: true

domain

String

The domain the browser is searching in

Default: local.

Whether or not the browser is currently searching

Default: false

The type of the service the browser searches for

Default: null

Methods 6

Inherited from Titanium.Proxy

Adds the specified callback as an event listener for the named event.

Parameters
ParametersTypeDescription
nameString

Name of the event.

callbackCallback<Titanium.Event>

Callback function to invoke when the event is fired.

4 fields
bubbles Boolean

True if the event will try to bubble up if possible.

cancelBubble Boolean

Set to true to stop the event from bubbling.

source Object

Source object that fired the event.

type String

Name of the event fired.

Inherited from Titanium.Proxy

Fires a synthesized event to any registered listeners.

Parameters
ParametersTypeDescription
nameString

Name of the event.

event?Dictionary

A dictionary of keys and values to add to the Titanium.Event object sent to the listeners.

Inherited from Titanium.Proxy

Removes the specified callback as an event listener for the named event.

Parameters
ParametersTypeDescription
nameString

Name of the event.

callbackCallback<Titanium.Event>

Callback function to remove. Must be the same function passed to addEventListener.

4 fields
bubbles Boolean

True if the event will try to bubble up if possible.

cancelBubble Boolean

Set to true to stop the event from bubbling.

source Object

Source object that fired the event.

type String

Name of the event fired.

Events 1

updatedservices

since 3.0.0

Fired when the discovered services list is updated

Event properties
Event propertiesTypeDescription
servicesArray<Titanium.Network.BonjourService>

An array of BonjourService objects corresponding to currently available services. If you cache this value, including using it as table data, be aware that it could become out of date at any time due to the asynchronous nature of Bonjour service discovery.