forked from praves77/cordova-plugin-android-idfa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request praves77#5 from Switch168/ios
Add iOS support
- Loading branch information
Showing
4 changed files
with
152 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#import <AdSupport/AdSupport.h> | ||
#import <Cordova/CDV.h> | ||
|
||
@interface AndroidIDFA : CDVPlugin | ||
|
||
- (void)getAdId:(CDVInvokedUrlCommand*)command; | ||
|
||
- (void)getIDFV:(CDVInvokedUrlCommand*)command; | ||
|
||
- (void)getLimitAd:(CDVInvokedUrlCommand*)command; | ||
|
||
- (void)getAdInfo:(CDVInvokedUrlCommand*)command; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
#import "AndroidIDFA.h" | ||
#import <Cordova/CDV.h> | ||
|
||
@implementation AndroidIDFA | ||
|
||
|
||
// Returns advertisingIdentifier as string | ||
// Will return error on iOS < 6.0 since AdSupport framwork doesn't exist | ||
- (void)getAdId:(CDVInvokedUrlCommand*)command | ||
{ | ||
[self.commandDelegate runInBackground:^{ | ||
CDVPluginResult* pluginResult = nil; | ||
|
||
// throw error if on iOS < 6.0 | ||
if (NSClassFromString(@"ASIdentifierManager")) { | ||
|
||
NSString *advertiserID = [[(id)[NSClassFromString(@"ASIdentifierManager") sharedManager] advertisingIdentifier] UUIDString]; | ||
|
||
// have to handle iOS bug where 00000000-0000-0000-0000-000000000000 may be returned on iOS 6.0 | ||
if (advertiserID != nil && [advertiserID length] > 0 && ![advertiserID isEqualToString:@"00000000-0000-0000-0000-000000000000"]) { | ||
NSDictionary *data = @{@"idfa" : advertiserID}; | ||
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:data]; | ||
} | ||
|
||
else { | ||
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR]; | ||
} | ||
} | ||
|
||
else { | ||
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR]; | ||
} | ||
|
||
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; | ||
|
||
}]; | ||
} | ||
|
||
// Returns identifierForAdvertising as string | ||
// Will return error on iOS < 6.0 since AdSupport framwork doesn't exist | ||
- (void)getIDFV:(CDVInvokedUrlCommand*)command | ||
{ | ||
[self.commandDelegate runInBackground:^{ | ||
CDVPluginResult* pluginResult = nil; | ||
|
||
// throw error if on iOS < 6.0 | ||
if (NSClassFromString(@"ASIdentifierManager")) { | ||
|
||
NSString *vendorID = [[[UIDevice currentDevice] identifierForVendor] UUIDString]; | ||
|
||
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:vendorID]; | ||
} | ||
|
||
else { | ||
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR]; | ||
} | ||
|
||
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; | ||
|
||
}]; | ||
} | ||
|
||
// Returns advertisingTrackingEnabled as boolean | ||
// Will return error on iOS < 6.0 since AdSupport framwork doesn't exist | ||
- (void)getLimitAd:(CDVInvokedUrlCommand*)command | ||
{ | ||
[self.commandDelegate runInBackground:^{ | ||
CDVPluginResult* pluginResult = nil; | ||
|
||
if (NSClassFromString(@"ASIdentifierManager")) { | ||
|
||
BOOL enabled = [[NSClassFromString(@"ASIdentifierManager") sharedManager] isAdvertisingTrackingEnabled]; | ||
NSDictionary *data = @{@"limitAd" : [NSNumber numberWithBool:!enabled]}; | ||
|
||
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:data]; | ||
|
||
} else { | ||
|
||
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR]; | ||
|
||
} | ||
|
||
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; | ||
|
||
}]; | ||
} | ||
|
||
// Returns dictionary containing idfa and tracking enabled bool | ||
// Will return error on iOS < 6.0 since AdSupport framwork doesn't exist | ||
- (void)getAdInfo:(CDVInvokedUrlCommand*)command | ||
{ | ||
[self.commandDelegate runInBackground:^{ | ||
CDVPluginResult* pluginResult = nil; | ||
|
||
// throw error if on iOS < 6.0 | ||
if (NSClassFromString(@"ASIdentifierManager")) { | ||
|
||
NSString *advertiserID = [[(id)[NSClassFromString(@"ASIdentifierManager") sharedManager] advertisingIdentifier] UUIDString]; | ||
|
||
NSString *vendorID = [[[UIDevice currentDevice] identifierForVendor] UUIDString]; | ||
|
||
BOOL enabled = [[NSClassFromString(@"ASIdentifierManager") sharedManager] isAdvertisingTrackingEnabled]; | ||
|
||
// have to handle iOS bug where 00000000-0000-0000-0000-000000000000 may be returned on iOS 6.0 | ||
// set advertiserID to an empty string | ||
if ([advertiserID isEqualToString:@"00000000-0000-0000-0000-000000000000"]) { | ||
advertiserID = @""; | ||
} | ||
|
||
NSDictionary *adData = @{ | ||
@"idfa" : advertiserID, | ||
@"idfv" : vendorID, | ||
@"limitAd" : [NSNumber numberWithBool:!enabled] | ||
}; | ||
|
||
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:adData]; | ||
} else { | ||
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR]; | ||
} | ||
|
||
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; | ||
|
||
}]; | ||
} | ||
@end |