Last Updated on : 2024-06-18 01:32:36download
Detection alerts can be enabled for smart devices. In most cases, a real-time video screenshot is uploaded to the cloud if a detection alert is generated. IPC SDK is designed to encrypt this image and attach it to the result of querying an alert message or cloud storage event. The component ThingEncryptImage
must be used to display this encrypted image.
Use UIImageView
to add the API method for displaying the encrypted images. For more information about the API definitions, see UIImageView+ThingAESImage.h
.
API description
- (void)thing_setAESImageWithPath:(NSString *)imagePath
encryptKey:(NSString *)encryptKey;
Parameters
Parameter | Description |
---|---|
imagePath | The URL of the image. |
encryptKey | The encryption key. |
API description
- (void)thing_setAESImageWithPath:(NSString *)imagePath
encryptKey:(NSString *)encryptKey
placeholderImage:(UIImage *)placeholderImage;
Parameters
Parameter | Description |
---|---|
placeholderImage | The placeholder image that appears before the encrypted image is loaded. |
API description
- (void)thing_setAESImageWithPath:(NSString *)imagePath
encryptKey:(NSString *)encryptKey
completed:(nullable ThingEncryptWebImageCompletionBlock)completedBlock;
Parameters
Parameter | Description |
---|---|
completedBlock | The callback to be invoked when the encrypted image is loaded. |
In an alert, the value of the attached image ThingSmartCameraMessageModel.attachPic
consists of the image URL and encryption key. Both sections are concatenated in the format of {path}@{key}
. To display the encrypted image, this concatenated string is divided to get the decryption data.
If the string is not suffixed with @{key}
, the attached image is not encrypted.
Example
#import <ThingSmartCameraKit/ThingSmartCameraKit.h>
#import <ThingEncryptImage/ThingEncryptImage.h>
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
}
ThingSmartCameraMessageModel *messageModel = [self.messageModelList objectAtIndex:indexPath.row];
NSArray *components = [messageModel.attachPic componentsSeparatedByString:@"@"];
if (components.count != 2) {
[cell.imageView thing_setImageWithURL:[NSURL URLWithString:messageModel.attachPic] placeholderImage:[self placeHolder]];
}else {
[cell.imageView thing_setAESImageWithPath:components.firstObject encryptKey:components.lastObject placeholderImage:[self placeHolder]];
}
cell.imageView.frame = CGRectMake(0, 0, 88, 50);
cell.textLabel.text = messageModel.msgTitle;
cell.detailTextLabel.text = messageModel.msgContent;
return cell;
}
In cloud storage events, the value of the event screenshot ThingSmartCloudTimeEventModel.snapshotUrl
is the complete URL of the image, and the key uses the unified key for cloud-stored video playback.
Example
#import <ThingSmartCameraKit/ThingSmartCameraKit.h>
#import <ThingEncryptImage/ThingEncryptImage.h>
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSDateFormatter *formatter = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"HH:mm:ss";
});
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"event"];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"event"];
}
ThingSmartCloudTimeEventModel *eventModel = [self.eventModels objectAtIndex:indexPath.row];
[cell.imageView thing_setAESImageWithPath:eventModel.snapshotUrl encryptKey:self.cloudManager.encryptKey placeholderImage:[self placeholder]];
cell.textLabel.text = eventModel.describe;
cell.detailTextLabel.text = [formatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:eventModel.startTime]];
return cell;
}
Download an encrypted image using the ThingEncryptImageDownloader
class. For more information about the API definitions, see ThingEncryptImageDownloader.h
.
API description
+ (instancetype)sharedManager;
API description
- (void)downloadEncryptImageWithPath:(NSString *)imagePath
encryptKey:(nullable NSString *)encryptKey
completed:(nullable ThingEncryptWebImageCompletionBlock)completedBlock;
Parameters
Parameter | Description |
---|---|
imagePath | The URL of the image. |
encryptKey | The encryption key. |
completedBlock | The callback to be invoked when the image download completes. |
Example
#import <ThingEncryptImage/ThingEncryptImage.h>
- (void)downloadEncryptImageWithPath:(NSString *)imagePath encryptKey:(nullable NSString *)encryptKey {
[[ThingEncryptImageDownloader sharedManager] downloadEncryptImageWithPath:imagePath encryptKey:encryptKey completed:^(UIImage * _Nullable image, NSURL * _Nullable url, ThingEncryptWebImageFromType from, ThingEncryptWebImageStage stage, NSError * _Nullable error) {
if (image) {
NSLog(@"download success");
}else {
NSLog(@"download error(%@)",error);
}
}];
}
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback