Use 6-digit codes
By default, Cobrowse does not require any visible UI presented to the user. It will exist in the background of your app, and only activate when agents initiate a new session.
You may optionally present a UI in your app that enables users to generate 6-digit codes. Users may then read a code over the phone or in chat, and agents can use the 6-digit code to initiate the Cobrowse session.
Important: 6-digit codes expire after approximately 15 minutes, so it's best practice to generate a code only when a user wants to start a session.
To generate a 6-digit code in your integration you can use the following APIs. Once you have generated the code you can display it to the user in your own UI. You should only generate a code when a user needs it as they expire shortly after creation.
Web
iOS / MacOS
React Native
Android
Xamarin
Windows
1
// ensure Cobrowse is loaded
2
CobrowseIO.client().then(function() {
3
// create a code a display it to the user using your own UI
4
CobrowseIO.createSessionCode().then(function(code) {
5
console.log('your code is', code);
6
});
7
});
Copied!
If you are only using 6 digit codes to start Cobrowse sessions in your implementation, you can add the following option to your call to CobrowseIO.start() in the default snippet we provide. This will prevent our SDK contacting the Cobrowse server until a screen sharing session is required.
1
CobrowseIO.start({register:false})
Copied!
1
[CobrowseIO.instance createSession:^(NSError * err, CBIOSession * session) {
2
if (err) NSLog(@"Failed to create code")
3
else NSLog(@"%@", session.code);
4
}];
Copied!
1
const session = await CobrowseIO.createSession()
2
console.log('Your 6 digit code is', session.code)
Copied!
1
CobrowseIO.instance().createSession((err, session) -> {
2
if (err != null) Log.w("App", "Failed to create code");
3
else if (session != null) Log.i("App", "Session code " + session.code());
4
});
Copied!
1
CobrowseIO.Instance.CreateSession((Exception err, ISession session) => {
2
if (err != null) Debug.WriteLine("Failed to create a code");
3
else if (session != null) Debug.WriteLine("Session code " + session.Code);
4
});
Copied!
1
Session session = await CobrowseIO.Instance.CreateSession();
2
Console.WriteLine("Code: {0}", session.Code);
Copied!
You can monitor changes in the state of the session using the Cobrowse delegate methods to listen for events:

Default 6-digit code UI

We provide a very simple default plug-and-play UI that provides the 6-digit code display functionality. We also provide a set of public methods if you prefer to build a custom UI (see above). Learn more at Customize the interface.
Web
iOS
Android
React Native
Xamarin
MacOS
Windows
The Cobrowse.io SDK for web does not provide a default UI for generating 6 digit codes.
  1. 1.
    Add the appropriate code below into a view controller in your app.
  2. 2.
    Hook up a trigger for the action (or call it programatically if you prefer).

Swift

1
import CobrowseIO
2
3
class ExampleViewController: UIViewController {
4
var sessionController: CBIOViewController!
5
6
@IBAction func startCobrowse(sender: UIBarButtonItem) {
7
self.sessionController = CBIOViewController()
8
self.navigationController?.pushViewController(self.sessionController, animated: true)
9
}
10
11
// ... the rest of your view controller
12
}
Copied!
For a full example written in Swift, see our Listr sample app at: https://github.com/cobrowseio/Listr

Objective C

1
@import CobrowseIO;
2
3
@implementation ExampleViewController {
4
CBIOViewController* sessionController;
5
}
6
7
-(IBAction) startCobrowse:(id)sender {
8
sessionController = [[CBIOViewController alloc] init];
9
[self.navigationController pushViewController:sessionController animated:YES];
10
}
11
12
// ... the rest of your view controller
13
14
@end
Copied!
Make sure you've hooked up a trigger for the startCobrowse IBAction that we've just added. Then head to https://cobrowse.io/dashboard and enter the 6 digit code that will be generated by your app when you trigger the action!
1
import io.cobrowse.ui.CobrowseActivity;
2
3
public class YourActivity extends Activity {
4
5
// the rest of your Activity
6
7
public void startCobrowse(View view) {
8
Intent intent = new Intent(this, CobrowseActivity.class);
9
startActivity(intent);
10
}
11
}
Copied!
Make sure you've hooked up a trigger for the startCobrowse method that we've just added. Then head to https://cobrowse.io/dashboard and enter the 6 digit code that will be generated by your app when you trigger the action!
We've provided a view that will do all the session creation and management for you. All you need to do is include this somewhere in your react native view hierarchy. It's not a requirement to use this UI, you can easily build your own if you like!
1
import { CobrowseView } from 'cobrowse-sdk-react-native';
2
3
export default class App extends Component {
4
render() {
5
return (
6
<View>
7
<CobrowseView />
8
</View>
9
);
10
}
11
}
Copied!

Xamarin.iOS implementation

  1. 1.
    Add the appropriate code below into a view controller in your app.
  2. 2.
    Hook up a trigger for the action (or call it programatically if you prefer).
1
using Xamarin.CobrowseIO;
2
3
namespace SampleApp.iOS
4
{
5
public partial class ViewController : UIViewController
6
{
7
private void StartCobrowse(object sender, EventArgs e)
8
{
9
NavigationController.PushViewController(new CobrowseViewController(), animated: true);
10
}
11
}
12
}
Copied!
For a full example written in C#, see our sample app at: https://github.com/cobrowseio/cobrowse-sdk-xamarin

Xamarin.Android implementation

We have provided some default UI to make things easier to get started:
1
using Xamarin.CobrowseIO;
2
using Xamarin.CobrowseIO.UI;
3
4
namespace SampleApp.Android
5
{
6
[Activity]
7
public class MainActivity : AppCompatActivity
8
{
9
private void StartCobrowse(object sender, EventArgs e)
10
{
11
var intent = new Intent(this, typeof(CobrowseActivity));
12
StartActivity(intent);
13
}
14
}
15
}
Copied!

Xamarin.Forms implementation

The Cobrowse.io Xamarin SDK provides a convenient way to open the default 6 digit code UI. In your cross-platform project:
1
using Xamarin.CobrowseIO.Abstractions;
2
3
namespace YourAppNamespace.Forms
4
{
5
public partial class YourPage : Xamarin.Forms.Page
6
{
7
public void StartCobrowse()
8
{
9
CobrowseIO.Instance.OpenCobrowseUI();
10
}
11
}
12
}
Copied!
The Cobrowse.io SDK for MacOS does not provide a default UI for generating 6 digit codes.
The Cobrowse.io SDK for Windows does not provide a default UI for generating 6 digit codes, instead you can generate a code for your UI by using the CreateSession API.
A complete example of a WPF integration is available here.
To see some code samples for how to build a custom UI for your platform see:
Copy link