iOS - add API

1.增加延迟启动 API
2.增加 doc 说明
3.优化代码
This commit is contained in:
pikacode
2016-12-15 14:51:15 +08:00
parent 30fbc6094f
commit eb0595e5c0
8 changed files with 82 additions and 11 deletions
+1
View File
@@ -12,4 +12,5 @@
@interface AppDelegate (JPush) <JPUSHRegisterDelegate>
-(void)registerForRemoteNotification;
-(void)startJPushSDK;
@end
+25 -2
View File
@@ -28,6 +28,8 @@
return [self init_plus];
}
NSDictionary *_launchOptions;
-(void)applicationDidLaunch:(NSNotification *)notification{
if (notification) {
if (notification.userInfo) {
@@ -41,11 +43,25 @@
}
}
[JPUSHService setDebugMode];
[self registerForRemoteNotification];
[JPushPlugin setupJPushSDK:notification.userInfo];
NSString *plistPath = [[NSBundle mainBundle] pathForResource:JPushConfig_FileName ofType:@"plist"];
NSMutableDictionary *plistData = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
NSNumber *delay = [plistData valueForKey:JPushConfig_Delay];
_launchOptions = notification.userInfo;
if (![delay boolValue]) {
[self startJPushSDK];
}
}
}
-(void)startJPushSDK{
[self registerForRemoteNotification];
[JPushPlugin setupJPushSDK:_launchOptions];
}
-(void)registerForRemoteNotification{
if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {
#ifdef NSFoundationVersionNumber_iOS_9_x_Max
@@ -100,11 +116,18 @@
-(void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler{
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:notification.request.content.userInfo];
if ([SharedJPushPlugin respondsToSelector:@selector(jpushFireDocumentEvent:jsString:)]) {
}
[SharedJPushPlugin jpushFireDocumentEvent:JPushDocumentEvent_ReceiveNotification jsString:[userInfo toJsonString]];
completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert);
}
-(void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler{
if ([SharedJPushPlugin respondsToSelector:@selector(jpushFireDocumentEvent:jsString:)]) {
}
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:response.notification.request.content.userInfo];
@try {
[userInfo setValue:[response valueForKey:@"userText"] forKey:@"userText"];
+2 -1
View File
@@ -15,11 +15,12 @@
#define WEAK_SELF(weakSelf) __weak __typeof(&*self)weakSelf = self;
static NSString *const JPushConfig_FileName = @"PushConfig";
static NSString *const JPushConfig_Appkey = @"Appkey";
static NSString *const JPushConfig_Channel = @"Channel";
static NSString *const JPushConfig_IsProduction = @"IsProduction";
static NSString *const JPushConfig_IsIDFA = @"IsIDFA";
static NSString *const JPushConfig_FileName = @"PushConfig";
static NSString *const JPushConfig_Delay = @"Delay";
static NSString *const JPushDocumentEvent_ReceiveNotification = @"receiveNotification";
static NSString *const JPushDocumentEvent_OpenNotification = @"openNotification";
+3
View File
@@ -12,6 +12,9 @@
}
//注册通知服务并启动 SDK
-(void)startJPushSDK:(CDVInvokedUrlCommand*)command;
//以下为js中可调用接口
//设置标签、别名
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command;
+16 -7
View File
@@ -39,6 +39,10 @@
@implementation JPushPlugin
-(void)startJPushSDK:(CDVInvokedUrlCommand*)command{
[(AppDelegate*)[UIApplication sharedApplication].delegate startJPushSDK];
}
#pragma mark- 外部接口
-(void)stopPush:(CDVInvokedUrlCommand*)command{
[[UIApplication sharedApplication]unregisterForRemoteNotifications];
@@ -55,18 +59,13 @@
-(void)initial:(CDVInvokedUrlCommand*)command{
//do nithng,because Cordova plugin use lazy load mode.
SharedJPushPlugin = self;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(networkDidReceiveMessage:)
name:kJPFNetworkDidReceiveMessageNotification
object:nil];
}
#ifdef __CORDOVA_4_0_0
- (void)pluginInitialize {
NSLog(@"### pluginInitialize ");
SharedJPushPlugin = self;
[self initPlugin];
}
#else
@@ -75,12 +74,22 @@
NSLog(@"### initWithWebView ");
if (self=[super initWithWebView:theWebView]) {
}
SharedJPushPlugin = self;
[self initPlugin];
return self;
}
#endif
-(void)initPlugin{
if (!SharedJPushPlugin) {
SharedJPushPlugin = self;
}
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(networkDidReceiveMessage:)
name:kJPFNetworkDidReceiveMessageNotification
object:nil];
}
-(void)jpushFireDocumentEvent:(NSString*)eventName jsString:(NSString*)jsString{
dispatch_async(dispatch_get_main_queue(), ^{
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.%@',%@)", eventName, jsString]];