summaryrefslogtreecommitdiff
path: root/Example Apps
diff options
context:
space:
mode:
authorNicoleYarroch <nicole@livio.io>2020-11-25 10:09:14 -0500
committerNicoleYarroch <nicole@livio.io>2020-11-25 10:09:14 -0500
commita20bf0b2c4ceebe62f642fb8a45e95075b6d2706 (patch)
treea85ad22e97f025823b8e2a95c11ea95fca3bca61 /Example Apps
parent84ae726ceae55a49a70a52133e8f0db1bf8c696a (diff)
downloadsdl_ios-a20bf0b2c4ceebe62f642fb8a45e95075b6d2706.tar.gz
Ex. apps now use the alert mng
Signed-off-by: NicoleYarroch <nicole@livio.io>
Diffstat (limited to 'Example Apps')
-rw-r--r--Example Apps/Example ObjC/AlertManager.m27
-rw-r--r--Example Apps/Example Swift/AlertManager.swift19
2 files changed, 25 insertions, 21 deletions
diff --git a/Example Apps/Example ObjC/AlertManager.m b/Example Apps/Example ObjC/AlertManager.m
index 9ee13fcdd..00973c082 100644
--- a/Example Apps/Example ObjC/AlertManager.m
+++ b/Example Apps/Example ObjC/AlertManager.m
@@ -15,19 +15,24 @@ NS_ASSUME_NONNULL_BEGIN
@implementation AlertManager
+ (void)sendAlertWithManager:(SDLManager *)sdlManager image:(nullable NSString *)imageName textField1:(NSString *)textField1 textField2:(nullable NSString *)textField2 {
- SDLSoftButton *okSoftButton = [[SDLSoftButton alloc] initWithType:SDLSoftButtonTypeText text:AlertOKButtonText image:nil highlighted:YES buttonId:1 systemAction:nil handler:nil];
- SDLAlert *alert = [[SDLAlert alloc] initWithAlertText1:textField1 alertText2:textField2 alertText3:nil softButtons:@[okSoftButton] playTone:YES ttsChunks:nil duration:5000 progressIndicator:NO alertIcon:nil cancelID:0];
+ SDLSoftButtonObject *okSoftButton = [[SDLSoftButtonObject alloc] initWithName:AlertOKButtonText text:AlertOKButtonText artwork:nil handler:nil];
- if (imageName == nil) {
- [sdlManager sendRequest:alert];
- } else {
- [self sdlex_sendImageWithName:imageName sdlManager:sdlManager completionHandler:^(BOOL success, NSString * _Nullable artworkName) {
- if (success) {
- alert.alertIcon = [[SDLImage alloc] initWithName:artworkName isTemplate:YES];
- }
- [sdlManager sendRequest:alert];
- }];
+ SDLAlertView *alert = [[SDLAlertView alloc] initWithText:textField1 buttons:@[okSoftButton]];
+ alert.secondaryText = textField2;
+
+ SDLAlertAudioData *alertAudioData = [[SDLAlertAudioData alloc] initWithSpeechSynthesizerString:@"alert"];
+ alertAudioData.playTone = YES;
+ alert.audio = alertAudioData;
+
+ if (imageName != nil) {
+ alert.icon = [SDLArtwork artworkWithImage:[[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] asImageFormat:SDLArtworkImageFormatPNG];
}
+
+ [sdlManager.screenManager presentAlert:alert withCompletionHandler:^(NSError * _Nullable error) {
+ if (error != nil) {
+ SDLLogD(@"There was an error presenting the alert: %@", error.localizedDescription);
+ }
+ }];
}
+ (void)sendSubtleAlertWithManager:(SDLManager *)sdlManager image:(nullable NSString *)imageName textField1:(NSString *)textField1 textField2:(nullable NSString *)textField2 {
diff --git a/Example Apps/Example Swift/AlertManager.swift b/Example Apps/Example Swift/AlertManager.swift
index 9e37dd1c5..df1fcd430 100644
--- a/Example Apps/Example Swift/AlertManager.swift
+++ b/Example Apps/Example Swift/AlertManager.swift
@@ -8,6 +8,7 @@
import Foundation
import SmartDeviceLink
+import SmartDeviceLinkSwift
class AlertManager {
/// Sends an alert with up to two lines of text, an image, and a close button that will dismiss the alert when tapped.
@@ -17,18 +18,16 @@ class AlertManager {
/// - textField2: The second line of text in the alert
/// - sdlManager: The SDLManager
class func sendAlert(imageName: String? = nil, textField1: String, textField2: String? = nil, sdlManager: SDLManager) {
- let okSoftButton = SDLSoftButton(type: .text, text: AlertOKButtonText, image: nil, highlighted: true, buttonId: 1, systemAction: nil, handler: nil)
- let alert = SDLAlert(alertText1: textField1, alertText2: textField2, alertText3: nil, softButtons: [okSoftButton], playTone: true, ttsChunks: nil, duration: 5000, progressIndicator: false, alertIcon: nil, cancelID: 0)
-
+ let okSoftButton = SDLSoftButtonObject(name: AlertOKButtonText, text: AlertOKButtonText, artwork: nil, handler: nil)
+ let alert = SDLAlertView(text: textField1, buttons: [okSoftButton])
+ alert.secondaryText = textField2
if let imageName = imageName {
- sendImage(imageName, sdlManager: sdlManager) { (success, artworkName) in
- if success {
- alert.alertIcon = SDLImage(name: artworkName, isTemplate: true)
- }
- sdlManager.send(alert)
+ alert.icon = SDLArtwork(image: UIImage(named: imageName)!.withRenderingMode(.alwaysTemplate), persistent: false, as: .PNG)
+ }
+ sdlManager.screenManager.presentAlert(alert) { error in
+ if let error = error {
+ SDLLog.e("There was an error presenting the alert: \(error.localizedDescription)")
}
- } else {
- sdlManager.send(alert)
}
}