@@ -596,7 +596,13 @@ - (void)shGetFeedDataFromServer:(CDVInvokedUrlCommand *)command
596596 {
597597 if (self.callbackCommandForFetchFeeds )
598598 {
599- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsArray: arrayFeeds];
599+ // arrayFeeds's element is SHFeedObject which is not compatible with NSJSONSerialization. Convert to NSDictionary to make Phonegap work.
600+ NSMutableArray *arrayDict = [NSMutableArray arrayWithCapacity: arrayFeeds.count];
601+ for (SHFeedObject *feedObj in arrayFeeds)
602+ {
603+ [arrayDict addObject: [feedObj serializeToDictionary ]];
604+ }
605+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsArray: arrayDict];
600606 [pluginResult setKeepCallbackAsBool: YES ];
601607 [self .commandDelegate sendPluginResult: pluginResult callbackId: self .callbackCommandForFetchFeeds.callbackId];
602608 }
@@ -626,9 +632,17 @@ - (void)shReportFeedAck:(CDVInvokedUrlCommand *)command
626632#ifdef SH_FEATURE_FEED
627633 if (command.arguments .count == 1 )
628634 {
629- if ([command.arguments[0 ] isKindOfClass: [NSNumber class ]])
635+ if ([command.arguments[0 ] isKindOfClass: [NSNumber class ]] || [command.arguments[ 0 ] isKindOfClass: [ NSString class ]] )
630636 {
631- NSInteger feedId = [command.arguments[0 ] integerValue ];
637+ NSString *feedId = nil ;
638+ if ([command.arguments[0 ] isKindOfClass: [NSNumber class ]])
639+ {
640+ feedId = [NSString stringWithFormat: @" %ld " , (long )[command.arguments[0 ] integerValue ]];
641+ }
642+ else
643+ {
644+ feedId = command.arguments [0 ];
645+ }
632646 [StreetHawk sendFeedAck: feedId];
633647 pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK];
634648 }
@@ -655,17 +669,26 @@ - (void)shReportFeedResult:(CDVInvokedUrlCommand *)command
655669#ifdef SH_FEATURE_FEED
656670 if (command.arguments .count == 2 )
657671 {
658- if ([command.arguments[0 ] isKindOfClass: [NSNumber class ]] && [command.arguments[1 ] isKindOfClass: [NSNumber class ]])
672+ if (([command.arguments[0 ] isKindOfClass: [NSNumber class ]] || [command.arguments[0 ] isKindOfClass: [NSString class ]])
673+ && [command.arguments[1 ] isKindOfClass: [NSNumber class ]])
659674 {
660- NSInteger feedId = [command.arguments[0 ] integerValue ];
675+ NSString *feedId = nil ;
676+ if ([command.arguments[0 ] isKindOfClass: [NSNumber class ]])
677+ {
678+ feedId = [NSString stringWithFormat: @" %ld " , (long )[command.arguments[0 ] integerValue ]];
679+ }
680+ else
681+ {
682+ feedId = command.arguments [0 ];
683+ }
661684 NSInteger feedResult = [command.arguments[1 ] integerValue ];
662685 if (feedResult < -1 || feedResult > 1 )
663686 {
664687 pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsString: @" Feed result should be: 1 for accept, 0 for postpone, -1 for decline." ];
665688 }
666689 else
667690 {
668- [StreetHawk sendLogForFeed : feedId withResult: (SHResult)feedResult];
691+ [StreetHawk notifyFeedResult : feedId withResult: (SHResult)feedResult];
669692 pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK];
670693 }
671694 }
@@ -686,6 +709,63 @@ - (void)shReportFeedResult:(CDVInvokedUrlCommand *)command
686709 [self .commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
687710}
688711
712+ - (void )notifyFeedResult : (CDVInvokedUrlCommand *)command
713+ {
714+ CDVPluginResult *pluginResult = nil ;
715+ #ifdef SH_FEATURE_FEED
716+ if (command.arguments .count == 5 )
717+ {
718+ if (([command.arguments[0 ] isKindOfClass: [NSNumber class ]] || [command.arguments[0 ] isKindOfClass: [NSString class ]])
719+ && [command.arguments[1 ] isKindOfClass: [NSString class ]]
720+ && [command.arguments[2 ] isKindOfClass: [NSString class ]]
721+ && [command.arguments[3 ] isKindOfClass: [NSNumber class ]]
722+ && [command.arguments[4 ] isKindOfClass: [NSNumber class ]])
723+ {
724+ NSString *feedId = nil ;
725+ if ([command.arguments[0 ] isKindOfClass: [NSNumber class ]])
726+ {
727+ feedId = [NSString stringWithFormat: @" %ld " , (long )[command.arguments[0 ] integerValue ]];
728+ }
729+ else
730+ {
731+ feedId = command.arguments [0 ];
732+ }
733+ NSString *stepId = command.arguments [1 ];
734+ NSString *result = command.arguments [2 ];
735+ BOOL deleted = [command.arguments[3 ] boolValue ];
736+ BOOL completed = [command.arguments[4 ] boolValue ];
737+ SHResult feedResult = SHResult_Accept;
738+ if ([result.lowercaseString containsString: @" accepted" ])
739+ {
740+ feedResult = SHResult_Accept;
741+ }
742+ else if ([result.lowercaseString containsString: @" postponed" ])
743+ {
744+ feedResult = SHResult_Postpone;
745+ }
746+ else if ([result.lowercaseString containsString: @" rejected" ])
747+ {
748+ feedResult = SHResult_Decline;
749+ }
750+ [StreetHawk notifyFeedResult: feedId withResult: feedResult withStepId: stepId deleteFeed: deleted completed: completed];
751+ }
752+ else
753+ {
754+ pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsString: @" Parameters expect [feedId_int, stepId_string, feedResult_string, feedDelete_bool, completed_bool]." ];
755+ }
756+ }
757+ else
758+ {
759+ pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsString: @" Wrong number of parameters, expect 5." ];
760+ }
761+ #else
762+ NSString *missPluginMsg = @" \" notifyFeedResult\" fail. Please add com.streethawk.feed plugin." ;
763+ NSLog (@" %@ " , missPluginMsg);
764+ pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsString: missPluginMsg];
765+ #endif
766+ [self .commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
767+ }
768+
689769- (void )originateShareWithCampaign : (CDVInvokedUrlCommand *)command
690770{
691771 CDVPluginResult *pluginResult = nil ;
0 commit comments