summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2017-03-09 09:45:51 -0500
committerGitHub <noreply@github.com>2017-03-09 09:45:51 -0500
commit1d0a94c92c610b971b07a95a7d53a9ab1f074fa1 (patch)
tree4f21ab9f6e4f623cbd5a274dfd200145ad319bc2
parent1fca00636bad1dfb222f8ed84028654f09f885dd (diff)
parent48e4429ca4267f003f23b2f5e7b4ef6f649f2811 (diff)
downloadsdl_ios-1d0a94c92c610b971b07a95a7d53a9ab1f074fa1.tar.gz
Merge pull request #546 from smartdevicelink/feature/issue_537_handler_specificity
Implement SDL 0027 - Increase Specificity of Handler Events
-rw-r--r--SmartDeviceLink-iOS.xcodeproj/project.pbxproj12
-rw-r--r--SmartDeviceLink/SDLAddCommand.h15
-rw-r--r--SmartDeviceLink/SDLAddCommand.m8
-rw-r--r--SmartDeviceLink/SDLNotificationConstants.h31
-rw-r--r--SmartDeviceLink/SDLRequestHandler.h33
-rw-r--r--SmartDeviceLink/SDLResponseDispatcher.h6
-rw-r--r--SmartDeviceLink/SDLResponseDispatcher.m15
-rw-r--r--SmartDeviceLink/SDLSoftButton.h9
-rw-r--r--SmartDeviceLink/SDLSoftButton.m4
-rw-r--r--SmartDeviceLink/SDLSubscribeButton.h17
-rw-r--r--SmartDeviceLink/SDLSubscribeButton.m4
-rw-r--r--SmartDeviceLink/SmartDeviceLink.h1
-rw-r--r--SmartDeviceLinkTests/DevAPISpecs/SDLResponseDispatcherSpec.m14
-rw-r--r--SmartDeviceLink_Example/Classes/ProxyManager.m12
14 files changed, 76 insertions, 105 deletions
diff --git a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj
index 566a56bcc..9a1924377 100644
--- a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj
+++ b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj
@@ -761,7 +761,6 @@
5D61FE141A84238C00846EE7 /* SDLWiperStatus.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D61FC271A84238C00846EE7 /* SDLWiperStatus.m */; };
5D6CC8EF1C610E660027F60A /* SDLSecurityType.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D6CC8EE1C610E660027F60A /* SDLSecurityType.h */; settings = {ATTRIBUTES = (Public, ); }; };
5D6EB4CC1BF28DC600693731 /* NSMapTable+SubscriptingSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D6EB4CB1BF28DC600693731 /* NSMapTable+SubscriptingSpec.m */; };
- 5D6F7A2B1BC45BF70070BF37 /* SDLRequestHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D6F7A2A1BC45BF70070BF37 /* SDLRequestHandler.h */; settings = {ATTRIBUTES = (Public, ); }; };
5D6F7A2E1BC5650B0070BF37 /* SDLLifecycleConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D6F7A2C1BC5650B0070BF37 /* SDLLifecycleConfiguration.h */; settings = {ATTRIBUTES = (Public, ); }; };
5D6F7A2F1BC5650B0070BF37 /* SDLLifecycleConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D6F7A2D1BC5650B0070BF37 /* SDLLifecycleConfiguration.m */; };
5D6F7A351BC5B9B60070BF37 /* SDLLockScreenViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D6F7A331BC5B9B60070BF37 /* SDLLockScreenViewController.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -1768,7 +1767,6 @@
5D61FC271A84238C00846EE7 /* SDLWiperStatus.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDLWiperStatus.m; sourceTree = "<group>"; };
5D6CC8EE1C610E660027F60A /* SDLSecurityType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDLSecurityType.h; sourceTree = "<group>"; };
5D6EB4CB1BF28DC600693731 /* NSMapTable+SubscriptingSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSMapTable+SubscriptingSpec.m"; path = "DevAPISpecs/NSMapTable+SubscriptingSpec.m"; sourceTree = "<group>"; };
- 5D6F7A2A1BC45BF70070BF37 /* SDLRequestHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDLRequestHandler.h; sourceTree = "<group>"; };
5D6F7A2C1BC5650B0070BF37 /* SDLLifecycleConfiguration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDLLifecycleConfiguration.h; sourceTree = "<group>"; };
5D6F7A2D1BC5650B0070BF37 /* SDLLifecycleConfiguration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDLLifecycleConfiguration.m; sourceTree = "<group>"; };
5D6F7A331BC5B9B60070BF37 /* SDLLockScreenViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDLLockScreenViewController.h; sourceTree = "<group>"; };
@@ -3419,7 +3417,6 @@
isa = PBXGroup;
children = (
5D6F7A301BC5B7100070BF37 /* Lock Screen UI */,
- 5DA3F3611BC448690026F2D0 /* Handler Additions */,
5DA3F3561BC4480E0026F2D0 /* Utilities */,
5D8204171BCD80A200D0A41B /* Configurations */,
5DBAE0A61D355EF200CE00BF /* Managers */,
@@ -3463,14 +3460,6 @@
name = Notifications;
sourceTree = "<group>";
};
- 5DA3F3611BC448690026F2D0 /* Handler Additions */ = {
- isa = PBXGroup;
- children = (
- 5D6F7A2A1BC45BF70070BF37 /* SDLRequestHandler.h */,
- );
- name = "Handler Additions";
- sourceTree = "<group>";
- };
5DAE06711BDEC68700F9B498 /* Developer API Tests */ = {
isa = PBXGroup;
children = (
@@ -3981,7 +3970,6 @@
5D61FE051A84238C00846EE7 /* SDLVehicleDataResultCode.h in Headers */,
5D61FD2B1A84238C00846EE7 /* SDLPerformInteractionResponse.h in Headers */,
5D61FDA11A84238C00846EE7 /* SDLSoftButtonCapabilities.h in Headers */,
- 5D6F7A2B1BC45BF70070BF37 /* SDLRequestHandler.h in Headers */,
5D61FDB51A84238C00846EE7 /* SDLSyncMsgVersion.h in Headers */,
5DA102A41D4122C700C15826 /* NSMutableDictionary+SafeRemove.h in Headers */,
5D61FE031A84238C00846EE7 /* SDLVehicleDataResult.h in Headers */,
diff --git a/SmartDeviceLink/SDLAddCommand.h b/SmartDeviceLink/SDLAddCommand.h
index fb7ea7498..509ea80fa 100644
--- a/SmartDeviceLink/SDLAddCommand.h
+++ b/SmartDeviceLink/SDLAddCommand.h
@@ -5,10 +5,9 @@
#import "SDLImageType.h"
#import "SDLNotificationConstants.h"
-#import "SDLRequestHandler.h"
-@class SDLMenuParams;
@class SDLImage;
+@class SDLMenuParams;
/**
* This class will add a command to the application's Command Menu SDLMenuParams
@@ -37,7 +36,7 @@
NS_ASSUME_NONNULL_BEGIN
-@interface SDLAddCommand : SDLRPCRequest <SDLRequestHandler>
+@interface SDLAddCommand : SDLRPCRequest
/**
* Construct a SDLAddCommand with a handler callback when an event occurs.
@@ -46,20 +45,20 @@ NS_ASSUME_NONNULL_BEGIN
*
* @return An SDLAddCommand object
*/
-- (instancetype)initWithHandler:(nullable SDLRPCNotificationHandler)handler;
+- (instancetype)initWithHandler:(nullable SDLRPCCommandNotificationHandler)handler;
-- (instancetype)initWithId:(UInt32)commandId vrCommands:(nullable NSArray<NSString *> *)vrCommands handler:(nullable SDLRPCNotificationHandler)handler;
+- (instancetype)initWithId:(UInt32)commandId vrCommands:(nullable NSArray<NSString *> *)vrCommands handler:(nullable SDLRPCCommandNotificationHandler)handler;
-- (instancetype)initWithId:(UInt32)commandId vrCommands:(nullable NSArray<NSString *> *)vrCommands menuName:(NSString *)menuName handler:(SDLRPCNotificationHandler)handler;
+- (instancetype)initWithId:(UInt32)commandId vrCommands:(nullable NSArray<NSString *> *)vrCommands menuName:(NSString *)menuName handler:(SDLRPCCommandNotificationHandler)handler;
-- (instancetype)initWithId:(UInt32)commandId vrCommands:(nullable NSArray<NSString *> *)vrCommands menuName:(NSString *)menuName parentId:(UInt32)parentId position:(UInt16)position iconValue:(NSString *)iconValue iconType:(SDLImageType)iconType handler:(nullable SDLRPCNotificationHandler)handler;
+- (instancetype)initWithId:(UInt32)commandId vrCommands:(nullable NSArray<NSString *> *)vrCommands menuName:(NSString *)menuName parentId:(UInt32)parentId position:(UInt16)position iconValue:(NSString *)iconValue iconType:(SDLImageType)iconType handler:(nullable SDLRPCCommandNotificationHandler)handler;
/**
* A handler that will let you know when the button you created is subscribed.
*
* @warning This will only work if you use SDLManager.
*/
-@property (nullable, copy, nonatomic) SDLRPCNotificationHandler handler;
+@property (nullable, copy, nonatomic) SDLRPCCommandNotificationHandler handler;
/**
* @abstract A Unique Command ID that identifies the command
diff --git a/SmartDeviceLink/SDLAddCommand.m b/SmartDeviceLink/SDLAddCommand.m
index 8c491359b..bfec12164 100644
--- a/SmartDeviceLink/SDLAddCommand.m
+++ b/SmartDeviceLink/SDLAddCommand.m
@@ -19,7 +19,7 @@ NS_ASSUME_NONNULL_BEGIN
return self;
}
-- (instancetype)initWithHandler:(nullable SDLRPCNotificationHandler)handler {
+- (instancetype)initWithHandler:(nullable SDLRPCCommandNotificationHandler)handler {
self = [self init];
if (!self) {
return nil;
@@ -30,7 +30,7 @@ NS_ASSUME_NONNULL_BEGIN
return self;
}
-- (instancetype)initWithId:(UInt32)commandId vrCommands:(nullable NSArray<NSString *> *)vrCommands handler:(nullable SDLRPCNotificationHandler)handler {
+- (instancetype)initWithId:(UInt32)commandId vrCommands:(nullable NSArray<NSString *> *)vrCommands handler:(nullable SDLRPCCommandNotificationHandler)handler {
self = [self init];
if (!self) {
return nil;
@@ -43,7 +43,7 @@ NS_ASSUME_NONNULL_BEGIN
return self;
}
-- (instancetype)initWithId:(UInt32)commandId vrCommands:(nullable NSArray<NSString *> *)vrCommands menuName:(NSString *)menuName handler:(SDLRPCNotificationHandler)handler {
+- (instancetype)initWithId:(UInt32)commandId vrCommands:(nullable NSArray<NSString *> *)vrCommands menuName:(NSString *)menuName handler:(SDLRPCCommandNotificationHandler)handler {
self = [self initWithId:commandId vrCommands:vrCommands handler:handler];
if (!self) {
return nil;
@@ -54,7 +54,7 @@ NS_ASSUME_NONNULL_BEGIN
return self;
}
-- (instancetype)initWithId:(UInt32)commandId vrCommands:(nullable NSArray<NSString *> *)vrCommands menuName:(NSString *)menuName parentId:(UInt32)parentId position:(UInt16)position iconValue:(NSString *)iconValue iconType:(SDLImageType)iconType handler:(nullable SDLRPCNotificationHandler)handler {
+- (instancetype)initWithId:(UInt32)commandId vrCommands:(nullable NSArray<NSString *> *)vrCommands menuName:(NSString *)menuName parentId:(UInt32)parentId position:(UInt16)position iconValue:(NSString *)iconValue iconType:(SDLImageType)iconType handler:(nullable SDLRPCCommandNotificationHandler)handler {
self = [self initWithId:commandId vrCommands:vrCommands menuName:menuName handler:handler];
if (!self) {
return nil;
diff --git a/SmartDeviceLink/SDLNotificationConstants.h b/SmartDeviceLink/SDLNotificationConstants.h
index 63fad1b25..8b9c748ac 100644
--- a/SmartDeviceLink/SDLNotificationConstants.h
+++ b/SmartDeviceLink/SDLNotificationConstants.h
@@ -7,6 +7,10 @@
//
#import <Foundation/Foundation.h>
+
+@class SDLOnButtonEvent;
+@class SDLOnButtonPress;
+@class SDLOnCommand;
@class SDLRPCNotification;
@class SDLRPCResponse;
@class SDLRPCRequest;
@@ -27,13 +31,6 @@ typedef NSString *SDLNotificationUserInfoKey;
#pragma mark - Blocks
/**
- * A handler used on certain RPCs, primarily buttons or commands, when an event occurs.
- *
- * @param notification The RPC Notification that was fired.
- */
-typedef void (^SDLRPCNotificationHandler)(__kindof SDLRPCNotification *notification);
-
-/**
* A handler used on all RPC requests which fires when the response is received.
*
* @param request The request which was sent.
@@ -42,6 +39,26 @@ typedef void (^SDLRPCNotificationHandler)(__kindof SDLRPCNotification *notificat
*/
typedef void (^SDLResponseHandler)(__kindof SDLRPCRequest *__nullable request, __kindof SDLRPCResponse *__nullable response, NSError *__nullable error);
+
+/**
+ A handler that may optionally be run when an SDLSubscribeButton or SDLSoftButton has a corresponding notification occur.
+
+ @warning This only works if you send the RPC using SDLManager.
+ @warning Only one of the two parameters will be set for each block call.
+
+ @param buttonPress An SDLOnButtonPress object that corresponds to this particular button.
+ @param buttonEvent An SDLOnButtonEvent object that corresponds to this particular button.
+ */
+typedef void (^SDLRPCButtonNotificationHandler)(SDLOnButtonPress *_Nullable buttonPress, SDLOnButtonEvent *_Nullable buttonEvent);
+/**
+ A handler that may optionally be run when an SDLAddCommand has a corresponding notification occur.
+
+ @warning This only works if you send the RPC using SDLManager.
+
+ @param command An SDLOnCommand object that corresponds to this particular SDLAddCommand.
+ */
+typedef void (^SDLRPCCommandNotificationHandler)(SDLOnCommand *command);
+
/**
* The key used in all SDL NSNotifications to extract the response or notification from the userinfo dictionary.
*/
diff --git a/SmartDeviceLink/SDLRequestHandler.h b/SmartDeviceLink/SDLRequestHandler.h
deleted file mode 100644
index 64ee67b48..000000000
--- a/SmartDeviceLink/SDLRequestHandler.h
+++ /dev/null
@@ -1,33 +0,0 @@
-//
-// SDLRequestHandler.h
-// SmartDeviceLink-iOS
-//
-// Created by Joel Fischer on 10/6/15.
-// Copyright © 2015 smartdevicelink. All rights reserved.
-//
-
-#import <Foundation/Foundation.h>
-
-#import "SDLNotificationConstants.h"
-
-NS_ASSUME_NONNULL_BEGIN
-
-@protocol SDLRequestHandler <NSObject>
-
-/**
- * The handler that is added to any RPC implementing this protocol.
- */
-@property (nullable, copy, nonatomic) SDLRPCNotificationHandler handler;
-
-/**
- * A special init function on any RPC implementing this protocol.
- *
- * @param handler The handler to be called at specified times, such as events for buttons.
- *
- * @return An instance of the class implementing this protocol.
- */
-- (instancetype)initWithHandler:(nullable SDLRPCNotificationHandler)handler;
-
-@end
-
-NS_ASSUME_NONNULL_END
diff --git a/SmartDeviceLink/SDLResponseDispatcher.h b/SmartDeviceLink/SDLResponseDispatcher.h
index f89c5cc59..3e31662e0 100644
--- a/SmartDeviceLink/SDLResponseDispatcher.h
+++ b/SmartDeviceLink/SDLResponseDispatcher.h
@@ -38,17 +38,17 @@ NS_ASSUME_NONNULL_BEGIN
/**
* Holds a map of command ids and their corresponding blocks.
*/
-@property (strong, nonatomic, readonly) NSMapTable<SDLAddCommandCommandId *, SDLRPCNotificationHandler> *commandHandlerMap;
+@property (strong, nonatomic, readonly) NSMapTable<SDLAddCommandCommandId *, SDLRPCCommandNotificationHandler> *commandHandlerMap;
/**
* Holds a map of button names and their corresponding blocks.
*/
-@property (strong, nonatomic, readonly) NSMapTable<SDLSubscribeButtonName *, SDLRPCNotificationHandler> *buttonHandlerMap;
+@property (strong, nonatomic, readonly) NSMapTable<SDLSubscribeButtonName *, SDLRPCButtonNotificationHandler> *buttonHandlerMap;
/**
* Holds a map of soft button ids and their corresponding blocks.
*/
-@property (strong, nonatomic, readonly) NSMapTable<SDLSoftButtonId *, SDLRPCNotificationHandler> *customButtonHandlerMap;
+@property (strong, nonatomic, readonly) NSMapTable<SDLSoftButtonId *, SDLRPCButtonNotificationHandler> *customButtonHandlerMap;
/**
* Create a new response dispatcher.
diff --git a/SmartDeviceLink/SDLResponseDispatcher.m b/SmartDeviceLink/SDLResponseDispatcher.m
index 09cfab31d..98df4a731 100644
--- a/SmartDeviceLink/SDLResponseDispatcher.m
+++ b/SmartDeviceLink/SDLResponseDispatcher.m
@@ -176,9 +176,8 @@ NS_ASSUME_NONNULL_BEGIN
- (void)sdl_runHandlerForCommand:(SDLRPCNotificationNotification *)notification {
SDLOnCommand *onCommandNotification = notification.notification;
- SDLRPCNotificationHandler handler = nil;
+ SDLRPCCommandNotificationHandler handler = self.commandHandlerMap[onCommandNotification.cmdID];
- handler = self.commandHandlerMap[onCommandNotification.cmdID];
if (handler) {
handler(onCommandNotification);
}
@@ -189,14 +188,14 @@ NS_ASSUME_NONNULL_BEGIN
- (void)sdl_runHandlerForButton:(SDLRPCNotificationNotification *)notification {
__kindof SDLRPCNotification *rpcNotification = notification.notification;
- SDLRPCNotificationHandler handler = nil;
+ SDLRPCButtonNotificationHandler handler = nil;
SDLButtonName name = nil;
NSNumber *customID = nil;
- if ([rpcNotification isKindOfClass:[SDLOnButtonEvent class]]) {
+ if ([rpcNotification isMemberOfClass:[SDLOnButtonEvent class]]) {
name = ((SDLOnButtonEvent *)rpcNotification).buttonName;
customID = ((SDLOnButtonEvent *)rpcNotification).customButtonID;
- } else if ([rpcNotification isKindOfClass:[SDLOnButtonPress class]]) {
+ } else if ([rpcNotification isMemberOfClass:[SDLOnButtonPress class]]) {
name = ((SDLOnButtonPress *)rpcNotification).buttonName;
customID = ((SDLOnButtonPress *)rpcNotification).customButtonID;
}
@@ -208,7 +207,11 @@ NS_ASSUME_NONNULL_BEGIN
}
if (handler) {
- handler(rpcNotification);
+ if ([rpcNotification isMemberOfClass:[SDLOnButtonEvent class]]) {
+ handler(nil, rpcNotification);
+ } else if ([rpcNotification isMemberOfClass:[SDLOnButtonPress class]]) {
+ handler(rpcNotification, nil);
+ }
}
}
diff --git a/SmartDeviceLink/SDLSoftButton.h b/SmartDeviceLink/SDLSoftButton.h
index a5cc9d7a4..398bf8053 100644
--- a/SmartDeviceLink/SDLSoftButton.h
+++ b/SmartDeviceLink/SDLSoftButton.h
@@ -4,7 +4,6 @@
#import "SDLRPCMessage.h"
#import "SDLNotificationConstants.h"
-#import "SDLRequestHandler.h"
#import "SDLSoftButtonType.h"
#import "SDLSystemAction.h"
@@ -12,13 +11,13 @@
NS_ASSUME_NONNULL_BEGIN
-@interface SDLSoftButton : SDLRPCStruct <SDLRequestHandler>
+@interface SDLSoftButton : SDLRPCStruct
-- (instancetype)initWithHandler:(nullable SDLRPCNotificationHandler)handler;
+- (instancetype)initWithHandler:(nullable SDLRPCButtonNotificationHandler)handler;
-- (instancetype)initWithType:(SDLSoftButtonType)type text:(nullable NSString *)text image:(nullable SDLImage *)image highlighted:(BOOL)highlighted buttonId:(UInt16)buttonId systemAction:(nullable SDLSystemAction)systemAction handler:(nullable SDLRPCNotificationHandler)handler;
+- (instancetype)initWithType:(SDLSoftButtonType)type text:(nullable NSString *)text image:(nullable SDLImage *)image highlighted:(BOOL)highlighted buttonId:(UInt16)buttonId systemAction:(nullable SDLSystemAction)systemAction handler:(nullable SDLRPCButtonNotificationHandler)handler;
-@property (copy, nonatomic) SDLRPCNotificationHandler handler;
+@property (copy, nonatomic) SDLRPCButtonNotificationHandler handler;
@property (strong, nonatomic) SDLSoftButtonType type;
@property (strong, nonatomic, nullable) NSString *text;
diff --git a/SmartDeviceLink/SDLSoftButton.m b/SmartDeviceLink/SDLSoftButton.m
index c33880c06..a50bb4bcd 100644
--- a/SmartDeviceLink/SDLSoftButton.m
+++ b/SmartDeviceLink/SDLSoftButton.m
@@ -11,7 +11,7 @@ NS_ASSUME_NONNULL_BEGIN
@implementation SDLSoftButton
-- (instancetype)initWithHandler:(nullable SDLRPCNotificationHandler)handler {
+- (instancetype)initWithHandler:(nullable SDLRPCButtonNotificationHandler)handler {
self = [self init];
if (!self) {
return nil;
@@ -22,7 +22,7 @@ NS_ASSUME_NONNULL_BEGIN
return self;
}
-- (instancetype)initWithType:(SDLSoftButtonType)type text:(nullable NSString *)text image:(nullable SDLImage *)image highlighted:(BOOL)highlighted buttonId:(UInt16)buttonId systemAction:(nullable SDLSystemAction)systemAction handler:(nullable SDLRPCNotificationHandler)handler {
+- (instancetype)initWithType:(SDLSoftButtonType)type text:(nullable NSString *)text image:(nullable SDLImage *)image highlighted:(BOOL)highlighted buttonId:(UInt16)buttonId systemAction:(nullable SDLSystemAction)systemAction handler:(nullable SDLRPCButtonNotificationHandler)handler {
self = [self initWithHandler:handler];
if (!self) {
return nil;
diff --git a/SmartDeviceLink/SDLSubscribeButton.h b/SmartDeviceLink/SDLSubscribeButton.h
index 6b3465636..11f25a8ea 100644
--- a/SmartDeviceLink/SDLSubscribeButton.h
+++ b/SmartDeviceLink/SDLSubscribeButton.h
@@ -1,12 +1,12 @@
// SDLSubscribeButton.h
//
-
+#import "SDLButtonName.h"
+#import "SDLNotificationConstants.h"
#import "SDLRPCRequest.h"
-#import "SDLButtonName.h"
-#import "SDLRequestHandler.h"
+NS_ASSUME_NONNULL_BEGIN
/**
* Establishes a subscription to button notifications for HMI buttons. Buttons
@@ -58,10 +58,7 @@
* Since SmartDeviceLink 1.0<br/>
* See SDLUnsubscribeButton
*/
-
-NS_ASSUME_NONNULL_BEGIN
-
-@interface SDLSubscribeButton : SDLRPCRequest <SDLRequestHandler>
+@interface SDLSubscribeButton : SDLRPCRequest
/**
* Construct a SDLSubscribeButton with a handler callback when an event occurs.
@@ -70,16 +67,16 @@ NS_ASSUME_NONNULL_BEGIN
*
* @return An SDLSubscribeButton object
*/
-- (instancetype)initWithHandler:(nullable SDLRPCNotificationHandler)handler;
+- (instancetype)initWithHandler:(nullable SDLRPCButtonNotificationHandler)handler;
-- (instancetype)initWithButtonName:(SDLButtonName)buttonName handler:(nullable SDLRPCNotificationHandler)handler;
+- (instancetype)initWithButtonName:(SDLButtonName)buttonName handler:(nullable SDLRPCButtonNotificationHandler)handler;
/**
* A handler that will let you know when the button you subscribed to is selected.
*
* @warning This will only work if you use SDLManager.
*/
-@property (copy, nonatomic) SDLRPCNotificationHandler handler;
+@property (copy, nonatomic) SDLRPCButtonNotificationHandler handler;
/**
* @abstract The name of the button to subscribe to
diff --git a/SmartDeviceLink/SDLSubscribeButton.m b/SmartDeviceLink/SDLSubscribeButton.m
index 07a2fe65c..1a94caa37 100644
--- a/SmartDeviceLink/SDLSubscribeButton.m
+++ b/SmartDeviceLink/SDLSubscribeButton.m
@@ -17,7 +17,7 @@ NS_ASSUME_NONNULL_BEGIN
return self;
}
-- (instancetype)initWithHandler:(nullable SDLRPCNotificationHandler)handler {
+- (instancetype)initWithHandler:(nullable SDLRPCButtonNotificationHandler)handler {
self = [self init];
if (!self) {
return nil;
@@ -28,7 +28,7 @@ NS_ASSUME_NONNULL_BEGIN
return self;
}
-- (instancetype)initWithButtonName:(SDLButtonName)buttonName handler:(nullable SDLRPCNotificationHandler)handler {
+- (instancetype)initWithButtonName:(SDLButtonName)buttonName handler:(nullable SDLRPCButtonNotificationHandler)handler {
self = [self init];
if (!self) {
return nil;
diff --git a/SmartDeviceLink/SmartDeviceLink.h b/SmartDeviceLink/SmartDeviceLink.h
index 9ca9975b4..ce6b9d5d4 100644
--- a/SmartDeviceLink/SmartDeviceLink.h
+++ b/SmartDeviceLink/SmartDeviceLink.h
@@ -309,7 +309,6 @@ FOUNDATION_EXPORT const unsigned char SmartDeviceLinkVersionString[];
#import "NSNumber+NumberType.h"
#import "SDLErrorConstants.h"
#import "SDLNotificationConstants.h"
-#import "SDLRequestHandler.h"
// Notifications
#import "SDLRPCNotificationNotification.h"
diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLResponseDispatcherSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLResponseDispatcherSpec.m
index ceb27c7d7..bcbc95631 100644
--- a/SmartDeviceLinkTests/DevAPISpecs/SDLResponseDispatcherSpec.m
+++ b/SmartDeviceLinkTests/DevAPISpecs/SDLResponseDispatcherSpec.m
@@ -126,7 +126,7 @@ describe(@"a response dispatcher", ^{
beforeEach(^{
numTimesHandlerCalled = 0;
- testSoftButton1 = [[SDLSoftButton alloc] initWithType:SDLSoftButtonTypeText text:@"test" image:nil highlighted:NO buttonId:1 systemAction:SDLSystemActionDefaultAction handler:^(__kindof SDLRPCNotification * _Nonnull notification) {
+ testSoftButton1 = [[SDLSoftButton alloc] initWithType:SDLSoftButtonTypeText text:@"test" image:nil highlighted:NO buttonId:1 systemAction:SDLSystemActionDefaultAction handler:^(SDLOnButtonPress * _Nullable buttonPressNotification, SDLOnButtonEvent * _Nullable buttonEventNotification) {
numTimesHandlerCalled++;
}];
testShow.softButtons = [@[testSoftButton1] mutableCopy];
@@ -199,7 +199,7 @@ describe(@"a response dispatcher", ^{
context(@"with a malformed soft button", ^{
beforeEach(^{
- testSoftButton1 = [[SDLSoftButton alloc] initWithType:SDLSoftButtonTypeText text:@"test" image:nil highlighted:NO buttonId:1 systemAction:SDLSystemActionDefaultAction handler:^(__kindof SDLRPCNotification * _Nonnull notification) {}];
+ testSoftButton1 = [[SDLSoftButton alloc] initWithType:SDLSoftButtonTypeText text:@"test" image:nil highlighted:NO buttonId:1 systemAction:SDLSystemActionDefaultAction handler:nil];
});
it(@"should throw an exception if there's no button id", ^{
@@ -355,7 +355,7 @@ describe(@"a response dispatcher", ^{
testSubscribeCorrelationId = @42;
numTimesHandlerCalled = 0;
- testSubscribeButton = [[SDLSubscribeButton alloc] initWithButtonName:testButtonName handler:^(__kindof SDLRPCNotification * _Nonnull notification) {
+ testSubscribeButton = [[SDLSubscribeButton alloc] initWithButtonName:testButtonName handler:^(SDLOnButtonPress * _Nullable buttonPressNotification, SDLOnButtonEvent * _Nullable buttonEventNotification) {
numTimesHandlerCalled++;
}];
testSubscribeButton.correlationID = testSubscribeCorrelationId;
@@ -485,7 +485,7 @@ describe(@"a response dispatcher", ^{
beforeEach(^{
numTimesHandlerCalled = 0;
- testSoftButton1 = [[SDLSoftButton alloc] initWithType:SDLSoftButtonTypeText text:@"test" image:nil highlighted:NO buttonId:1 systemAction:SDLSystemActionDefaultAction handler:^(__kindof SDLRPCNotification * _Nonnull notification) {
+ testSoftButton1 = [[SDLSoftButton alloc] initWithType:SDLSoftButtonTypeText text:@"test" image:nil highlighted:NO buttonId:1 systemAction:SDLSystemActionDefaultAction handler:^(SDLOnButtonPress * _Nullable buttonPressNotification, SDLOnButtonEvent * _Nullable buttonEventNotification) {
numTimesHandlerCalled++;
}];
@@ -558,7 +558,7 @@ describe(@"a response dispatcher", ^{
context(@"with a malformed soft button", ^{
beforeEach(^{
- testSoftButton1 = [[SDLSoftButton alloc] initWithType:SDLSoftButtonTypeText text:@"test" image:nil highlighted:NO buttonId:1 systemAction:SDLSystemActionDefaultAction handler:^(__kindof SDLRPCNotification * _Nonnull notification) {}];
+ testSoftButton1 = [[SDLSoftButton alloc] initWithType:SDLSoftButtonTypeText text:@"test" image:nil highlighted:NO buttonId:1 systemAction:SDLSystemActionDefaultAction handler:nil];
});
it(@"should throw an exception if there's no button id", ^{
@@ -596,7 +596,7 @@ describe(@"a response dispatcher", ^{
beforeEach(^{
numTimesHandlerCalled = 0;
- testSoftButton1 = [[SDLSoftButton alloc] initWithType:SDLSoftButtonTypeText text:@"test" image:nil highlighted:NO buttonId:1 systemAction:SDLSystemActionDefaultAction handler:^(__kindof SDLRPCNotification * _Nonnull notification) {
+ testSoftButton1 = [[SDLSoftButton alloc] initWithType:SDLSoftButtonTypeText text:@"test" image:nil highlighted:NO buttonId:1 systemAction:SDLSystemActionDefaultAction handler:^(SDLOnButtonPress * _Nullable buttonPressNotification, SDLOnButtonEvent * _Nullable buttonEventNotification) {
numTimesHandlerCalled++;
}];
@@ -669,7 +669,7 @@ describe(@"a response dispatcher", ^{
context(@"with a malformed soft button", ^{
beforeEach(^{
- testSoftButton1 = [[SDLSoftButton alloc] initWithType:SDLSoftButtonTypeText text:@"test" image:nil highlighted:NO buttonId:1 systemAction:SDLSystemActionDefaultAction handler:^(__kindof SDLRPCNotification * _Nonnull notification) {}];
+ testSoftButton1 = [[SDLSoftButton alloc] initWithType:SDLSoftButtonTypeText text:@"test" image:nil highlighted:NO buttonId:1 systemAction:SDLSystemActionDefaultAction handler:nil];
});
it(@"should throw an exception if there's no button id", ^{
diff --git a/SmartDeviceLink_Example/Classes/ProxyManager.m b/SmartDeviceLink_Example/Classes/ProxyManager.m
index 5139da20e..37bac20c1 100644
--- a/SmartDeviceLink_Example/Classes/ProxyManager.m
+++ b/SmartDeviceLink_Example/Classes/ProxyManager.m
@@ -272,12 +272,14 @@ NS_ASSUME_NONNULL_BEGIN
}
+ (SDLSoftButton *)pointingSoftButtonWithManager:(SDLManager *)manager {
- SDLSoftButton* softButton = [[SDLSoftButton alloc] initWithHandler:^(__kindof SDLRPCNotification *notification) {
- if ([notification isKindOfClass:[SDLOnButtonPress class]]) {
- SDLAlert* alert = [[SDLAlert alloc] init];
- alert.alertText1 = @"You pushed the button!";
- [manager sendRequest:alert];
+ SDLSoftButton* softButton = [[SDLSoftButton alloc] initWithHandler:^(SDLOnButtonPress * _Nullable buttonPressNotification, SDLOnButtonEvent * _Nullable buttonEventNotification) {
+ if (buttonPressNotification == nil) {
+ return;
}
+
+ SDLAlert* alert = [[SDLAlert alloc] init];
+ alert.alertText1 = @"You pushed the button!";
+ [manager sendRequest:alert];
}];
softButton.text = @"Press";
softButton.softButtonID = @100;