-
Notifications
You must be signed in to change notification settings - Fork 3
Basic Functions
To implement dynamic content or to use function like a login or native smartphone functions, you can use the JavaScript Library. With the binding of the JavaScript file, you will be able to get access to several chayns functions. This list contains basic chayns functions.
- chayns.login(parameters)
- chayns.logout(logoutType)
- chayns.addAccessTokenChangeListener(callback)
- chayns.removeAccessTokenChangeListener(callback)
- chayns.refreshAccessToken()
- chayns.activateAdminMode(callback)
- chayns.deactivateAdminMode(callback)
- chayns.addAdminSwitchListener(callback, forceReload)
- chayns.removeAdminSwitchListener(callback)
- chayns.getUser(config)
- chayns.allowRefreshScroll()
- chayns.disallowRefreshScroll()
- chayns.addOnActivateListener(callback)
- chayns.removeOnActivateListener(callback)
- chayns.addNetworkChangeListener(callback)
- chayns.removeNetworkChangeListener(callback)
- chayns.addNfcListener(callback)
- chayns.removeNfcListener(callback)
- chayns.scanQRCode()
- chayns.cancelScanQrCode()()
- chayns.createQRCode(text)
- chayns.navigateBack()
- chayns.selectTapp(tapp, parameter)
- chayns.openUrl(config)
- chayns.closeUrl()
- chayns.openUrlInBrowser(url)
- chayns.getGeoLocation()
- chayns.addGeoLocationListener(callback)
- chayns.removeGeoLocationListener(callback)
- chayns.getAvailableSharingServices()
- chayns.share(config)
- chayns.enableDisplayTimeout()
- chayns.disableDisplayTimeout()
- chayns.setSubTapp(config)
- chayns.removeSubTapp(config)
- chayns.vibrate(pattern)
- chayns.getWindowMetrics()
- chayns.addWindowMetricsListener(callback, startCall)
- chayns.removeWindowMetricsListener(callback)
- chayns.setHeight(config)
- chayns.scrollToY(position)
- chayns.addScrollListener(callback, throttle)
- chayns.removeScrollListener(callback, throttle)
- chayns.setScreenOrientation(orientation)
- chayns.findSite(name, skip, take)
- chayns.findUser(name, skip, take)
- chayns.getLastPushNotification()
- chayns.getWebviewOptions()
All functions listed below are supported on Android, iOS and in the chaynsWeb, if not mentioned separately.
Information: The intercom functions moved to the the intercom section.
This method will show a login dialog where the user has the opportunity to log in. After a successful login, the tapp will perform a reload by default. Check our snippet for a solution without reloading.
Parameter
- parameters : string[] - The parameters that will be passed to the chayns.env after logging in (use chayns.env.parameters).
chayns.login(["parameter=append"]);
This method will prevent reloading and sets a callback after switching the admin mode.
Parameter
- logoutType : int - The type to logout. chayns.logoutType contains the different formats and it specific values.
chayns.logout(chayns.logoutType.FORCE);
This method will prevent reloading and adds a callback to the queue of functions called after a login or logout.
Parameter
- callback: function - The function which will be added to the queue.
chayns.addAccessTokenChangeListener(console.log);
This method will remove a callback from the queue of function which will be called after a login or logout.
Parameter
- callback: function - The function which will be removed from the queue.
chayns.removeAccessTokenChangeListener(console.log);
This method will refresh the access token.
This method will activate the admin mode.
chayns.activateAdminMode();
This method will deactivate the admin mode.
chayns.deactivateAdminMode();
This method will prevent reloading and adds a callback to the queue of functions called after switching the admin mode. If the function is called with forceReload false the tapp will reload.
Parameter
- callback: function - The function which will be added to the queue.
chayns.addAdminSwitchListener(console.log);
This method will remove a callback from the queue of functions called after switching the admin mode.
Parameter
- callback: function - The function which will be removed from the queue.
chayns.removeAdminSwitchListener(console.log);
This method returns user information for a specific user. You have to provide one of the parameters listed below.
Parameter
- config : object - Has to contain one of the following parameters.
- accessToken : string - Use chayns.env.user.tobitAccessToken.
- userId : int - Use chayns.env.user.id.
- fbId : string - Only works if logged in via facebook. Use chayns.env.user.facebookId.
- personId : string - Use chayns.env.user.personId.
Result
- FacebookID : string - The id of the users facebook profile. Chayns users will get an empty string at this point.
- FirstName : string - The first name of the user.
- LastName : string - The last name of the user.
- PersonID : string - The personId of the user.
- UserFullName : string - Returns the full name.
- UserID : int - The userId of the user.
chayns.getUser({
'userId': chayns.env.user.id
}).then(console.log);
Enables pull down to refresh, if disabled using chayns.disallowRefreshScroll().
Supported Platforms
- Android
- iOS
- myChaynsApp
- chaynsWebMobile
chayns.allowRefreshScroll();
Disables pull down to refresh.
Supported Platforms
- Android
- iOS
- myChaynsApp
- chaynsWebMobile
chayns.disallowRefreshScroll();
This method adds a callback to a queue which will be executed when the tapp gets displayed or hidden. It returns an int value that lets you specify the event.
Supported Platforms
- Android
- iOS
- Web
Parameter
- callback : function - Will be added to the queue.
Result
- tappEvent : int - Values: Displayed(0), Hidden(1)
chayns.addOnActivateListener(console.log);
This method removes a callback from a queue which will be executed when the tapp gets displayed or hidden.
Supported Platforms
- Android
- iOS
- Web
Parameter
- callback : function - Will removed from the queue.
chayns.removeOnActivateListener(console.log);
This method allows you to watch the current network type and especially whether the user is connected to the internet.
Supported Platforms
- Android
- iOS
Parameter
- callback : function - Will be executed if the tapp gets displayed or hidden.
Result
- isConnected : boolean - Values: Connected(1), Disconnected(0)
- type : int - Values: No_Network(0), Network(1 to 17)
chayns.addNetworkChangeListener(console.log);
This method removes a callback from the networkChangeListener queue.
Supported Platforms
- Android
- iOS
Parameter
- callback : function - Will be removed from the queue.
chayns.removeNetworkChangeListener(console.log);
Starts NFC detection and adds a callback function to the queue, that will be called when a NFC device or card is getting in contact to the smartphone.
Supported Platforms
- Android
- myChaynsApp
Parameter
- callback : function(result) - Will be executed on nfc detection. It returns the detected id.
Result
- isConnected : boolean - Values: Connected(1), Disconnected(0)
- type : int - Values: No_Network(0), Network(1 to 17)
chayns.addNfcListener(console.log);
Removes a callback function from the queue, that will be called when a NFC device or card is getting in contact to the smartphone.
Supported Platforms
- Android
- myChaynsApp
Parameter
- callback : function(result) - Will be removed from the queue.
chayns.removeNfcListener(console.log);
This function activates the camera to scan a QR-Code. As result the QR-Code value will be returned in a promise.
Supported Platforms
- Android
- iOS
- myChaynsApp
Parameter
- cameraType (optional) : int - Define which camera to use. (0: default, 1: back, 2: front)
- timeout (optional) : int - Timeout in seconds after which the QR scan will be canceled.
//Use frontcamera(type: 1), cancel after 60 seconds
chayns.scanQRCode(1, 60).then(function(result) {
chayns.dialog.alert(null, result);
});
This function cancels the QR code scanning.
chayns.cancelScanQrCode();
Creates a QR code from a string that, for example, contains an URL to your website. In the web version it returns the Url to the generated image and in the apps the result will be a base64 encoded string-image.
Parameter
- text : string - The text to generate as qr code.
chayns.createQRCode('https://tobit.software').then(console.log);
This function navigates you to the previous site.
chayns.navigateBack();
Switch to another Tapp.
Parameter
- tapp : object - The id, internalName, showName or position of the tapp to switch to. You can also set a siteId if the tapp is on another site.
- parameter (optional) : string - Parameters that will be passed to the new tapp.
chayns.selectTapp({
'showName': 'Welcome!'
}, "parameter=set");
Opens an URL in the chayns environment.
Parameter
- config : object - Containing the following parameters.
- url : string - The URL of the website.
- title - (optional) : string - The title that will be showed on the top of the content of the Url.
- exclusiveView - (optional) : boolean - View without bars.
- darkenBackground - (optional/ only web) : boolean - Defines wether the background should be dark or not.
- fullSize - (optional/ only web) : boolean - Defines wether the Url should be opened in an full size or not.
- width - (optional/ only web) : number - Width of the opened window.
- chayns - (optional/ only app): boolean - Use location webView
chayns.openUrl({
url: 'https://en.tobit.software/chayns?tappId=1'
});
This method allows you to close an url that was opened by openUrl().
Supported Platforms
- Android
- iOS
chayns.closeUrl();
Opens a URL in the default browser.
Parameter
- url : string - The url of the resource to open.
chayns.openUrlInBrowser('https://tobit.software/');
This method determines your location. If you want to track a route, use addGeoLocationListener.
Result
-
longitude
: double - The longitude of the current position. -
latitude
: double - The latitude of the current position. -
accuracy
: double - The accuracy of the current position. -
isAccurate
: boolean - iOS-only. Whether the user has enabled precise location access.
In case of an error, the promise will be rejected with the following result:
-
code
: integer - The error code -
message
: string - The error message
chayns.getGeoLocation().then(function(result) {
chayns.dialog.alert(null, JSON.stringify(result));
}).catch(function(error){
chayns.dialog.alert("Error", JSON.stringify(error))
});
This adds a listener to determine your location.
This removes a listener to determine your location.
Returns the window metrics.
Supported Platforms
- ChaynsWeb
- Android
- iOS
Result
- height: int - the heigth
- scrollTop: int - height to scroll to top
- windowHeight: int - full height of the window
- pageYOffset: int - the y offset of the page
- frameX: int - the x offset of the tapp
- frameY: int - the y offset of the tapp
chayns.getWindowMetrics().then(console.log)
This adds a listener to get the actual height of the tapp. Set startCall to get the callback function called directly.
Supported Platforms
- ChaynsWeb
- Android
- iOS
Result
- int - the height
chayns.addWindowMetricsListener(console.log, true);
This removes a listener added using addWindowMetricsListener().
Supported Platforms
- ChaynsWeb
- Android
- iOS
chayns.removeWindowMetricsListener(console.log);
This method allows you to share an image or a text. SharingApps can be found in chayns.sharingApp or by using chayns.getAvailableSharingServices().
Supported Platforms
- Android
- iOS
Parameter
- config : object - An object containing the following parameters.
- title (optional) : string - Title of the message.
- text : string - Message body.
- imageUrl (optional) : string - Title of the message.
- sharingApp : int - App to share. See chayns.sharingApp.
- sharingAndroidApp (optional) : string - To share on specific application. Only for Android.
chayns.getAvailableSharingServices().then(function(result) {
chayns.share({
title: 'Title',
text: 'Text',
imageUrl: 'https://chayns.tobit.com/storage/60038-22141/Images/icon-57.png',
sharingApp: result.retVal.availableSharingApps[0]
});
});
This method returns a list of installed share/social media apps.
Supported Platforms
- Android
- iOS
Result
- availableSharingApps : int[] - An array containing internal ids for different sharing apps.
chayns.getAvailableSharingServices().then(console.log);
Re-enables the display timeout, so it will turn off after the system display timeout is reached. (If you have used chayns.disableDisplayTimeout() before)
Supported Platforms
- Android
- iOS
chayns.enableDisplayTimeout()
Disables the display timeout and keeps the display active. Re-enable it using chayns.enableDisplayTimeout().
Supported Platforms
- Android
- iOS
chayns.disableDisplayTimeout()
Creates and updates a new, temporary Tapp.
Parameter
-
config : object - Containg the following parameters.
-
tappID : int - ID for the new sub tapp
-
name : string - Name for Title
-
color : string - Color for the navigation
-
colorText - (optional) : string - Colortext for the navigation
-
sortID : int - To sort the Tapp on a specific place on the navigation. -1 sorts the Tapp to first position
-
icon : string - Use FontAwesome or FontTS as icon. Reference: http://fortawesome.github.io/Font-Awesome/3.2.1/icons/
-
callbackURL - (optional) : function(result) - After startup it will be checked, if the Tapp should be shown. If no callbackURL is added, the Tapp will removed on the next start
-
url : string - URL of the Tapp
-
buttonName : string - Name for the navigation button
-
isExclusiveView - (optional) : boolean - True for exclusive view. Default: false
-
replaceParent - (optional) : boolean - If this value is true, the executing Tapp will be replaced. After removing the sub Tapp, it will be shown again
-
boldText - (optional) : boolean - To show the navigation text in bold
chayns.setSubTapp({
'tappID': 76543,
'url': 'http://developers.chayns.net/FrontendSnippets',
'name': 'Snippets-Subtapp',
'color': '#ffff00',
'sortID': 8989,
'icon': 'fa-plus',
'buttonName': 'Button',
'replaceParent': true
});
Removes a sub Tapp with specified id.
Parameter
- config : object - Contains the following parameters.
- tappID : int - The id of the subtapp you want to close or remove.
- close : boolean - Set to true to close the subtapp.
- remove : boolean - Set to true to remove the subtapp.
chayns.removeSubTapp({
'tappID': 76543,
'close': true,
'remove': true
});
This method lets a smartphone vibrate for the given time.
Supported Platforms
- Android
- iOs
Parameter
- pattern : int[] - Vibration duration in ms. Default is 150ms. If you provide more than one value, the device will stop vibrating for a moment before each interval. Vibration duration is only supported on Android.
- iOSFeedbackVibration : int - Defines which iOS feedback style should be executed.
- SelectionChanged: 1
- NotificationError: 2
- NotificationSuccess: 3
- NotificationWarning: 4
- Light: 5
- Medium: 6
- Heavy: 7
- Soft: 8
- Rigid: 9
chayns.vibrate([1000, 100, 1000], 5);
Function to set the height of the iframe.
Supported Platforms
- ChaynsWeb
Parameter
- config : object - Containing the following parameters.
- height : int - Sets the height of the iframe.
- growOnly (optional) : boolean - If true, the iframe wont shrink if the content gets less.
- full (optional) : boolean - Overriding height with the mx height.
- fullViewport (optional) : boolean - Sets dynamic height.
chayns.setHeight({
'height': 500,
'growOnly': false
});
This method allows you to scroll vertically to a specific position in a tapp.
Supported Platforms
- ChaynsWeb
Parameter
- position : int - Y-position to scroll to
- duration : int - duration how long the scrolling should take
chayns.scrollToY(200,200);
Adds a listener for scroll event by user.
Supported Platforms
- ChaynsWeb
Parameter
- callback : function - The function that will get executed on scroll.
- throttle (Optional) : int - Event will be fired all (default 200) ms only.
chayns.addScrollListener(console.log);
Sets the orientation of the screen.
Supported Platforms
- Android
- iOS
Parameter
- orientation : int - Default: 0, Portrait: 1, Landscape: 2
chayns.setScreenOrientation(2)
This method allows you to search for chayns sites by name. It will return an array containing site objects.
Parameter
- name : string - The name or a part of the name of the site you are looking for.
- skip (optional) : int - Skips the specified number of the first results.
- take (otpional) : int - The max number of results you want to get.
Result
- appstoreName : string
- facebookId : string
- siteId : string
- locationId : int
chayns.findSite('Tobit.Software', 0, 5).then(console.log);
This method allows you to search for chayns users by name. It will return an array containing user objects.
Parameter
- name : string - The name or a part of the name of the user you are looking for.
- skip (optional) : int - Skips the specified number of the first results.
- take (otpional) : int - The max number of results you want to get.
Result
- currentLocationId : int
- facebookId : string
- lastLoginTime : string
- name : string
- personId : string
- userId : int
chayns.findPerson('Thomas Tobit', 0, 5).then(console.log);
This method gives you information about the last push notifications.
Supported Platforms
- Android
- iOS
chayns.getLastPushNotification().then(console.log);
This method gives you information about the web view.
Supported Platforms
- Android
- iOS
chayns.getWebviewOptions().then(console.log);
<!-- To get started.. -->
<!-- Load the chayns API styles and JavaScript from our server -->
<!-- css styles -->
<script src="https://api.chayns-static.space/css/v4/compatibility/compatibility.min.js" version="4.2"></script>
<!-- js api -->
<script src="https://api.chayns-static.space/js/v4.0/chayns.min.js"></script>