@@ -143,14 +143,32 @@ export function addBackgroundRemoteNotificationHandler(appDelegate) {
143143 } ;
144144}
145145
146- export function registerForInteractivePush ( model ?: any ) {
146+ export function registerForInteractivePush ( model ?: PushNotificationModel ) {
147147 let nativeActions : Array < UNNotificationAction > = [ ] ;
148148
149- model . iosSettings . interactiveSettings . actions . forEach ( action => {
150- let nativeAction = UNNotificationAction . actionWithIdentifierTitleOptions ( action . identifier , action . title , action . options | UNNotificationActionOptionNone ) ;
149+ model . iosSettings . interactiveSettings . actions . forEach ( ( ( action : IosInteractiveNotificationAction ) => {
150+ let notificationActionOptions : UNNotificationActionOptions = action . options ? < UNNotificationActionOptions > action . options . valueOf ( ) : UNNotificationActionOptionNone ;
151+ let actionType = action . type || "button" ;
152+ let nativeAction : UNNotificationAction ;
153+
154+ if ( actionType === "input" ) {
155+ nativeAction = UNTextInputNotificationAction . actionWithIdentifierTitleOptionsTextInputButtonTitleTextInputPlaceholder (
156+ action . identifier ,
157+ action . title ,
158+ notificationActionOptions ,
159+ action . submitLabel || "Submit" ,
160+ action . placeholder ) ;
161+ } else if ( actionType === "button" ) {
162+ nativeAction = UNNotificationAction . actionWithIdentifierTitleOptions (
163+ action . identifier ,
164+ action . title ,
165+ notificationActionOptions ) ;
166+ } else {
167+ console . log ( "Unsupported action type: " + action . type ) ;
168+ }
151169
152170 nativeActions . push ( nativeAction ) ;
153- } ) ;
171+ } ) ) ;
154172
155173 let actions : NSArray < UNNotificationAction > = < NSArray < UNNotificationAction > > NSArray . arrayWithArray ( < any > nativeActions ) ;
156174 let nativeCategories : Array < UNNotificationCategory > = [ ] ;
@@ -273,6 +291,9 @@ export enum IosInteractiveNotificationActionOptions {
273291export interface IosInteractiveNotificationAction {
274292 identifier : string ;
275293 title : string ;
294+ type : string ;
295+ submitLabel : string ;
296+ placeholder : string ;
276297 // activationMode?: string;
277298 // destructive?: boolean;
278299 // authenticationRequired?: boolean;
@@ -303,6 +324,11 @@ export class PushNotificationModel {
303324 iosSettings : IosPushSettings ;
304325 onNotificationActionTakenCallback : Function ;
305326}
327+ export class NotificationActionResponse {
328+ androidSettings : any ;
329+ iosSettings : IosPushSettings ;
330+ onNotificationActionTakenCallback : Function ;
331+ }
306332
307333export function areNotificationsEnabled ( ) {
308334 let app = iOSUtils . getter ( UIApplication , UIApplication . sharedApplication ) ;
@@ -345,7 +371,7 @@ function _registerForRemoteNotifications() {
345371 }
346372 } ) ;
347373
348- _userNotificationCenterDelegate = UNUserNotificationCenterDelegateImpl . new ( ) . initWithCallback ( ( unnotification , actionIdentifier ?) => {
374+ _userNotificationCenterDelegate = UNUserNotificationCenterDelegateImpl . new ( ) . initWithCallback ( ( unnotification , actionIdentifier ?, inputText ? ) => {
349375 // if the app is in the foreground then this method will receive the notification
350376 // if the app is in the background, and user has responded to interactive notification, then this method will receive the notification
351377 // if the app is in the background, and user views a notification, applicationDidReceiveRemoteNotificationFetchCompletionHandler will receive it
@@ -371,7 +397,7 @@ function _registerForRemoteNotifications() {
371397 userInfoJSON . aps = undefined ;
372398 // TODO: THIS CODE UP IS DUPLICATE, REFACTOR!!!!
373399
374- _notificationActionTakenCallback ( actionIdentifier , userInfoJSON ) ;
400+ _notificationActionTakenCallback ( actionIdentifier , userInfoJSON , inputText ) ;
375401 }
376402
377403 userInfoJSON . foreground = true ;
@@ -500,9 +526,9 @@ class UNUserNotificationCenterDelegateImpl extends NSObject implements UNUserNot
500526 return < UNUserNotificationCenterDelegateImpl > super . new ( ) ;
501527 }
502528
503- private callback : ( unnotification : UNNotification , actionIdentifier ?: string ) => void ;
529+ private callback : ( unnotification : UNNotification , actionIdentifier ?: string , inputText ?: string ) => void ;
504530
505- public initWithCallback ( callback : ( unnotification : UNNotification , actionIdentifier ?: string ) => void ) : UNUserNotificationCenterDelegateImpl {
531+ public initWithCallback ( callback : ( unnotification : UNNotification , actionIdentifier ?: string , inputText ?: string ) => void ) : UNUserNotificationCenterDelegateImpl {
506532 this . callback = callback ;
507533 return this ;
508534 }
@@ -524,9 +550,10 @@ class UNUserNotificationCenterDelegateImpl extends NSObject implements UNUserNot
524550 }
525551
526552 public userNotificationCenterDidReceiveNotificationResponseWithCompletionHandler ( center : UNUserNotificationCenter , response : UNNotificationResponse , completionHandler : ( ) => void ) : void {
527- console . log ( ">>>>>>>>>>> Handle push " ) ;
553+ console . log ( "Notification action response " ) ;
528554 console . log ( response ) ;
529- this . callback ( response . notification , response . actionIdentifier ) ;
555+
556+ this . callback ( response . notification , response . actionIdentifier , ( < UNTextInputNotificationResponse > response ) . userText ) ;
530557 completionHandler ( ) ;
531558 }
532559}
0 commit comments