This commit is contained in:
pikacode 2016-12-30 12:29:43 +08:00
parent df6adddc75
commit 6734bf9160
6 changed files with 26 additions and 24 deletions

View File

@ -39,7 +39,7 @@
<header-file src="src/ios/lib/JPUSHService.h" />
<source-file src="src/ios/lib/jpush-ios-3.0.0.a" framework="true" />
<source-file src="src/ios/lib/jcore-ios-1.0.0.a" framework="true" />
<resource-file src="src/ios/PushConfig.plist" />
<resource-file src="src/ios/JPushConfig.plist" />
<framework src="CFNetwork.framework" weak="true" />
<framework src="CoreFoundation.framework" weak="true" />

View File

@ -3,9 +3,9 @@
<plist version="1.0">
<dict>
<key>Appkey</key>
<string>1c29cb5814072b5b1f8ef829</string>
<string></string>
<key>Channel</key>
<string>Subscription</string>
<string>channel name</string>
<key>IsProduction</key>
<false/>
<key>IsIDFA</key>

View File

@ -31,15 +31,26 @@
NSDictionary *_launchOptions;
-(void)applicationDidLaunch:(NSNotification *)notification{
if (notification) {
if (notification.userInfo) {
NSDictionary *userInfo1 = [notification.userInfo valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (userInfo1.count > 0) {
[SharedJPushPlugin jpushFireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[userInfo1 toJsonString]];
[NSTimer scheduledTimerWithTimeInterval:0.1 repeats:YES block:^(NSTimer * _Nonnull timer) {
if (SharedJPushPlugin) {
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[userInfo1 toJsonString]];
[timer invalidate];
}
}];
}
NSDictionary *userInfo2 = [notification.userInfo valueForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (userInfo2.count > 0) {
[SharedJPushPlugin jpushFireDocumentEvent:JPushDocumentEvent_StartLocalNotification jsString:[userInfo1 toJsonString]];
[NSTimer scheduledTimerWithTimeInterval:0.1 repeats:YES block:^(NSTimer * _Nonnull timer) {
if (SharedJPushPlugin) {
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[userInfo2 toJsonString]];
[timer invalidate];
}
}];
}
}
[JPUSHService setDebugMode];
@ -91,7 +102,7 @@ NSDictionary *_launchOptions;
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
[JPUSHService handleRemoteNotification:userInfo];
[SharedJPushPlugin jpushFireDocumentEvent:JPushDocumentEvent_ReceiveNotification jsString:[userInfo toJsonString]];
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_ReceiveNotification jsString:[userInfo toJsonString]];
}
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
@ -110,30 +121,23 @@ NSDictionary *_launchOptions;
default:
break;
}
[SharedJPushPlugin jpushFireDocumentEvent:eventName jsString:[userInfo toJsonString]];
[JPushPlugin fireDocumentEvent:eventName jsString:[userInfo toJsonString]];
completionHandler(UIBackgroundFetchResultNewData);
}
-(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]];
[JPushPlugin fireDocumentEvent: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"];
} @catch (NSException *exception) { }
[userInfo setValue:response.actionIdentifier forKey:@"actionIdentifier"];
[SharedJPushPlugin jpushFireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[userInfo toJsonString]];
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[userInfo toJsonString]];
completionHandler();
}

View File

@ -15,7 +15,7 @@
#define WEAK_SELF(weakSelf) __weak __typeof(&*self)weakSelf = self;
static NSString *const JPushConfig_FileName = @"PushConfig";
static NSString *const JPushConfig_FileName = @"JPushConfig";
static NSString *const JPushConfig_Appkey = @"Appkey";
static NSString *const JPushConfig_Channel = @"Channel";
static NSString *const JPushConfig_IsProduction = @"IsProduction";

View File

@ -75,7 +75,7 @@
# pragma mark - private
-(void)jpushFireDocumentEvent:(NSString*)eventName jsString:(NSString*)jsString;
+(void)fireDocumentEvent:(NSString*)eventName jsString:(NSString*)jsString;
+(void)setupJPushSDK:(NSDictionary*)userInfo;

View File

@ -90,10 +90,8 @@
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]];
});
+(void)fireDocumentEvent:(NSString*)eventName jsString:(NSString*)jsString{
[SharedJPushPlugin.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.%@',%@)", eventName, jsString]];
}
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command{
@ -322,12 +320,12 @@
@"tags" :tags == nil ? [NSNull null] : [tags allObjects],
@"alias" :alias == nil ? [NSNull null] : alias
};
[self jpushFireDocumentEvent:JPushDocumentEvent_SetTagsWithAlias jsString:[dict toJsonString]];
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_SetTagsWithAlias jsString:[dict toJsonString]];
}
- (void)networkDidReceiveMessage:(NSNotification *)notification {
if (notification && notification.userInfo) {
[self jpushFireDocumentEvent:JPushDocumentEvent_ReceiveMessage jsString:[notification.userInfo toJsonString]];
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_ReceiveMessage jsString:[notification.userInfo toJsonString]];
}
}