mirror of
https://github.com/jpush/jpush-phonegap-plugin.git
synced 2025-02-23 06:42:58 +08:00
Optimize ios native methods
- setTags - setAlias - setTagsWithAlias
This commit is contained in:
parent
2a05ea1784
commit
2287ef10dd
@ -99,24 +99,45 @@
|
|||||||
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command{
|
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command{
|
||||||
NSString *alias = [command argumentAtIndex:0];
|
NSString *alias = [command argumentAtIndex:0];
|
||||||
NSArray *tags = [command argumentAtIndex:1];
|
NSArray *tags = [command argumentAtIndex:1];
|
||||||
|
|
||||||
[JPUSHService setTags:[NSSet setWithArray:tags]
|
[JPUSHService setTags:[NSSet setWithArray:tags]
|
||||||
alias:alias
|
alias:alias
|
||||||
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
|
fetchCompletionHandle:^(int iResCode, NSSet *iTags, NSString *iAlias) {
|
||||||
object:self];
|
CDVPluginResult *result;
|
||||||
|
if (iResCode == 0) {
|
||||||
|
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:nil];
|
||||||
|
} else {
|
||||||
|
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:nil];
|
||||||
|
}
|
||||||
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)setTags:(CDVInvokedUrlCommand *)command{
|
-(void)setTags:(CDVInvokedUrlCommand*)command{
|
||||||
NSArray *tags = command.arguments;
|
NSArray *tags = command.arguments;
|
||||||
[JPUSHService setTags:[NSSet setWithArray:tags]
|
[JPUSHService setTags:[NSSet setWithArray:tags]
|
||||||
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
|
alias:nil
|
||||||
object:self];
|
fetchCompletionHandle:^(int iResCode, NSSet *iTags, NSString *iAlias) {
|
||||||
|
CDVPluginResult *result;
|
||||||
|
if (iResCode == 0) {
|
||||||
|
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:nil];
|
||||||
|
} else {
|
||||||
|
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:nil];
|
||||||
|
}
|
||||||
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)setAlias:(CDVInvokedUrlCommand *)command{
|
-(void)setAlias:(CDVInvokedUrlCommand*)command{
|
||||||
NSString *alias = [command argumentAtIndex:0];
|
NSString *alias = [command argumentAtIndex:0];
|
||||||
[JPUSHService setAlias:alias
|
[JPUSHService setTags:nil
|
||||||
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
|
alias:alias
|
||||||
object:self];
|
fetchCompletionHandle:^(int iResCode, NSSet *iTags, NSString *iAlias) {
|
||||||
|
CDVPluginResult *result;
|
||||||
|
if (iResCode == 0) {
|
||||||
|
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:nil];
|
||||||
|
} else {
|
||||||
|
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:nil];
|
||||||
|
}
|
||||||
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)getRegistrationID:(CDVInvokedUrlCommand*)command{
|
-(void)getRegistrationID:(CDVInvokedUrlCommand*)command{
|
||||||
@ -149,12 +170,12 @@
|
|||||||
[JPUSHService resetBadge];
|
[JPUSHService resetBadge];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)setApplicationIconBadgeNumber:(CDVInvokedUrlCommand *)command{
|
-(void)setApplicationIconBadgeNumber:(CDVInvokedUrlCommand*)command{
|
||||||
NSNumber *badge = [command argumentAtIndex:0];
|
NSNumber *badge = [command argumentAtIndex:0];
|
||||||
[UIApplication sharedApplication].applicationIconBadgeNumber = badge.intValue;
|
[UIApplication sharedApplication].applicationIconBadgeNumber = badge.intValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)getApplicationIconBadgeNumber:(CDVInvokedUrlCommand *)command {
|
-(void)getApplicationIconBadgeNumber:(CDVInvokedUrlCommand*)command {
|
||||||
NSInteger num = [UIApplication sharedApplication].applicationIconBadgeNumber;
|
NSInteger num = [UIApplication sharedApplication].applicationIconBadgeNumber;
|
||||||
NSNumber *number = [NSNumber numberWithInteger:num];
|
NSNumber *number = [NSNumber numberWithInteger:num];
|
||||||
[self handleResultWithValue:number command:command];
|
[self handleResultWithValue:number command:command];
|
||||||
@ -252,16 +273,22 @@
|
|||||||
NSString *textInputPlaceholder = dict[@"textInputPlaceholder"];
|
NSString *textInputPlaceholder = dict[@"textInputPlaceholder"];
|
||||||
UNTextInputNotificationAction *inputAction = [UNTextInputNotificationAction actionWithIdentifier:identifier title:title options:option.integerValue textInputButtonTitle:textInputButtonTitle textInputPlaceholder:textInputPlaceholder];
|
UNTextInputNotificationAction *inputAction = [UNTextInputNotificationAction actionWithIdentifier:identifier title:title options:option.integerValue textInputButtonTitle:textInputButtonTitle textInputPlaceholder:textInputPlaceholder];
|
||||||
[actions addObject:inputAction];
|
[actions addObject:inputAction];
|
||||||
}else{
|
} else {
|
||||||
UNNotificationAction *action = [UNNotificationAction actionWithIdentifier:title title:title options:option.integerValue];
|
UNNotificationAction *action = [UNNotificationAction actionWithIdentifier:title title:title options:option.integerValue];
|
||||||
[actions addObject:action];
|
[actions addObject:action];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
UNNotificationCategory *category;
|
UNNotificationCategory *category;
|
||||||
if (dimiss) {
|
if (dimiss) {
|
||||||
category = [UNNotificationCategory categoryWithIdentifier:categoryId actions:actions intentIdentifiers:@[] options:UNNotificationCategoryOptionCustomDismissAction];
|
category = [UNNotificationCategory categoryWithIdentifier:categoryId
|
||||||
}else{
|
actions:actions
|
||||||
category = [UNNotificationCategory categoryWithIdentifier:categoryId actions:actions intentIdentifiers:@[] options:UNNotificationCategoryOptionNone];
|
intentIdentifiers:@[]
|
||||||
|
options:UNNotificationCategoryOptionCustomDismissAction];
|
||||||
|
} else {
|
||||||
|
category = [UNNotificationCategory categoryWithIdentifier:categoryId
|
||||||
|
actions:actions
|
||||||
|
intentIdentifiers:@[]
|
||||||
|
options:UNNotificationCategoryOptionNone];
|
||||||
}
|
}
|
||||||
[[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:[NSSet setWithObject:category]];
|
[[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:[NSSet setWithObject:category]];
|
||||||
}
|
}
|
||||||
@ -282,7 +309,7 @@
|
|||||||
NSNumber *isIDFA = [plistData valueForKey:JPushConfig_IsIDFA];
|
NSNumber *isIDFA = [plistData valueForKey:JPushConfig_IsIDFA];
|
||||||
|
|
||||||
NSString *advertisingId = nil;
|
NSString *advertisingId = nil;
|
||||||
if(isIDFA.boolValue){
|
if(isIDFA.boolValue) {
|
||||||
advertisingId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
|
advertisingId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
|
||||||
}
|
}
|
||||||
[JPUSHService setupWithOption:userInfo
|
[JPUSHService setupWithOption:userInfo
|
||||||
@ -293,7 +320,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark 将参数返回给js
|
#pragma mark 将参数返回给js
|
||||||
-(void)handleResultWithValue:(id)value command:(CDVInvokedUrlCommand*)command{
|
-(void)handleResultWithValue:(id)value command:(CDVInvokedUrlCommand*)command {
|
||||||
CDVPluginResult *result = nil;
|
CDVPluginResult *result = nil;
|
||||||
CDVCommandStatus status = CDVCommandStatus_OK;
|
CDVCommandStatus status = CDVCommandStatus_OK;
|
||||||
|
|
||||||
@ -317,17 +344,18 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark 设置标签及别名回调
|
#pragma mark 设置标签及别名回调
|
||||||
-(void)tagsWithAliasCallback:(int)resultCode tags:(NSSet *)tags alias:(NSString *)alias{
|
-(void)tagsWithAliasCallback:(int)resultCode tags:(NSSet *)tags alias:(NSString *)alias {
|
||||||
NSDictionary *dict = @{@"resultCode":[NSNumber numberWithInt:resultCode],
|
if (resultCode == 0) { // Success
|
||||||
@"tags" :tags == nil ? [NSNull null] : [tags allObjects],
|
|
||||||
@"alias" :alias == nil ? [NSNull null] : alias
|
} else {
|
||||||
};
|
|
||||||
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_SetTagsWithAlias jsString:[dict toJsonString]];
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)networkDidReceiveMessage:(NSNotification *)notification {
|
- (void)networkDidReceiveMessage:(NSNotification *)notification {
|
||||||
if (notification && notification.userInfo) {
|
if (notification && notification.userInfo) {
|
||||||
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_ReceiveMessage jsString:[notification.userInfo toJsonString]];
|
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_ReceiveMessage
|
||||||
|
jsString:[notification.userInfo toJsonString]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user