Skip to content

Commit

Permalink
Merge pull request #32 from raphagodoi/master
Browse files Browse the repository at this point in the history
update how to delegate commands to CDVPluginResult
  • Loading branch information
kraihn committed May 24, 2016
2 parents 13a6f73 + 9616318 commit c9b874c
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/ios/CDVTagManager.m
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/**
* Copyright (c) 2014 Jared Dickson
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -28,17 +28,17 @@ - (void) initGTM:(CDVInvokedUrlCommand*)command
NSString *callbackId = command.callbackId;
NSString *accountID = [command.arguments objectAtIndex:0];
NSInteger dispatchPeriod = [[command.arguments objectAtIndex:1] intValue];

inited = FALSE;
self.tagManager = [TAGManager instance];

// Modify the log level of the logger to print out not only
// warning and error messages, but also verbose, debug, info messages.
[self.tagManager.logger setLogLevel:kTAGLoggerLogLevelVerbose];

// Set the dispatch interval
self.tagManager.dispatchInterval = dispatchPeriod;

// Open a container.
[TAGContainerOpener openContainerWithId:accountID
tagManager:self.tagManager
Expand All @@ -60,10 +60,10 @@ - (void) containerAvailable:(TAGContainer *)container {
-(void) exitGTM:(CDVInvokedUrlCommand*)command
{
NSString *callbackId = command.callbackId;

if (inited)
[self.container close];

[self successWithMessage:@"exitGTM" toID:callbackId];
}

Expand All @@ -79,7 +79,7 @@ - (void) trackEvent:(CDVInvokedUrlCommand*)command
{
eventValue = [NSNumber numberWithInt:[valueObject intValue]];
}

if (inited)
{
TAGDataLayer *dataLayer = [TAGManager instance].dataLayer;
Expand All @@ -94,7 +94,7 @@ - (void) pushEvent:(CDVInvokedUrlCommand*)command
{
NSString *callbackId = command.callbackId;
NSDictionary *eventData = [command.arguments objectAtIndex:0];

if (inited)
{
TAGDataLayer *dataLayer = [TAGManager instance].dataLayer;
Expand All @@ -109,7 +109,7 @@ - (void) trackPage:(CDVInvokedUrlCommand*)command
{
NSString *callbackId = command.callbackId;
NSString *pageURL = [command.arguments objectAtIndex:0];

if (inited)
{
TAGDataLayer *dataLayer = [TAGManager instance].dataLayer;
Expand All @@ -134,16 +134,16 @@ - (void) dispatch:(CDVInvokedUrlCommand*)command
-(void) successWithMessage:(NSString *)message toID:(NSString *)callbackID
{
CDVPluginResult *commandResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:message];
[self writeJavascript:[commandResult toSuccessCallbackString:callbackID]];

[self.commandDelegate sendPluginResult:commandResult callbackId:callbackID];
}

-(void) failWithMessage:(NSString *)message toID:(NSString *)callbackID withError:(NSError *)error
{
NSString *errorMessage = (error) ? [NSString stringWithFormat:@"%@ - %@", message, [error localizedDescription]] : message;
CDVPluginResult *commandResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:errorMessage];
[self writeJavascript:[commandResult toErrorCallbackString:callbackID]];

[self.commandDelegate sendPluginResult:commandResult callbackId:callbackID];
}

-(void)dealloc
Expand Down

0 comments on commit c9b874c

Please sign in to comment.