Last Updated on : 2024-07-01 08:14:17
This tutorial will walk you through the basic features of a smart travel app, enabling you to kickstart the development process easily.
You can go to GitHub and download the sample code. This tutorial is broken down into sections based on features, making it easy for you to quickly locate the code.
App SDK Development GitHub Sample
The UI is built using the API from the Smart Travel SDK.
Before starting, ensure you have the following prepared.
Create a Tuya Developer Platform account and an app, with the AppKey
and AppSecret
ready. For more information, see Preparation.
The Smart Travel SDK depends on the Smart Life App SDK. Implement creating an account and adding a home before incorporating travel-specific features. For more information, see Quick Start with Smart Life App SDK.
Prepare a Tuya-enabled travel product. This tutorial demonstrates the process using a two-wheeler. Visit TuyaGo to explore Tuya-enabled products.
Integrate the Smart Life App SDK and Smart Travel SDK into your project using CocoaPods. For more information, see SDK Integration.
Tuya-enabled devices are controlled through bidirectional communication regarding a range of data points (DPs). The Smart Travel SDK is built using the DP methods from ThingSmartDevice
. It is recommended to use the following methods for controlling all travel-related DPs. If you are unfamiliar with the concept of DP, check out Device Control and Product Functions.
@interface ThingSmartDevice (ThingSmartOutdoor)
/// send DP with code
/// @param code DP code
/// @param DPValue the DP original value (NSString, NSNumber, NSDictionary)
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)tsod_publishDPWithCode:(NSString *)code
DPValue:(id)DPValue
success:(nullable ThingSuccessHandler)success
failure:(nullable ThingFailureError)failure;
@end
This example demonstrates how to use the basic APIs for automatic unlocking over Bluetooth. See Automatic Unlocking for details.
Automatic unlocking requires a Bluetooth connection. Verify if the app has permission to access the phone’s Bluetooth and the current connection status. If necessary, ask the user to enable it.
Check the pairing status for automatic unlocking:
ThingSmartDevice *device = [ThingSmartDevice deviceWithDeviceId:@"xxx"];
BOOL paired = [[ThingODBTInductiveUnlock sharedInstance] checkPairedStatus:device.devId];
if (paired) {
//TODO: The logic for paired status, such as displaying the interface for turning off automatic unlocking.
} else {
//TODO: The logic for not paired status, such as displaying the interface for turning on automatic unlocking.
}
Turn on automatic unlocking:
[[ThingODBTInductiveUnlock sharedInstance] addDelegate:self];
self.device = [ThingSmartDevice deviceWithDeviceId:@"xxx"];
[[ThingODBTInductiveUnlock sharedInstance] turnOnBTInductiveUnlock:self.devID finished:^{
//...
} error:^(NSError * _Nonnull error) {
}];
Delegate listener:
#pragma mark - delegate ThingODBTInductiveUnlockDelegate
- (void)btInductiveUnlock:(ThingODBTInductiveUnlock *)btInductiveUnlock deviceID:(NSString *)deviceID status:(BTUnlockPairStatus)status {
if (status == BTUnlockPairBindStatusSuccess) {
//TODO: Enabled successfully
}
}
Turn off automatic unlocking:
[[ThingODBTInductiveUnlock sharedInstance] turnOffBTInductiveUnlock:self.device.devId finished:^{
//TODO: Disabled successfully
} error:^(NSError * _Nonnull error) {
}];
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback