Compare commits

...

11 Commits

Author SHA1 Message Date
pikacode
423304c5dc Merge branch 'dev' 2016-12-15 16:02:27 +08:00
pikacode
5d7181a659 update package.json 2016-12-15 16:01:51 +08:00
pikacode
eb0595e5c0 iOS - add API
1.增加延迟启动 API
2.增加 doc 说明
3.优化代码
2016-12-15 14:51:15 +08:00
pikacode
c2f1bc86bf Merge branch 'dev' 2016-12-12 10:45:48 +08:00
pikacode
30fbc6094f iOS - fix #191 2016-12-12 10:41:38 +08:00
pikacode
d39dea2441 Merge branch 'dev' 2016-12-09 10:13:56 +08:00
pikacode
abfcd3c93a iOS - update
1.fix a bug
2016-12-08 15:31:13 +08:00
pikacode
399d159757 Merge branch 'dev' 2016-12-08 10:34:48 +08:00
pikacode
b96e36d6aa iOS - fix #188 2016-12-08 10:33:36 +08:00
Hevin
78310e5c69 Merge remote-tracking branch 'refs/remotes/origin/dev' 2016-12-07 00:20:56 +08:00
Hevin
fbad235605 Update README
更新 README 徽章中的版本号。
2016-12-07 00:12:36 +08:00
10 changed files with 86 additions and 8 deletions

View File

@@ -2,7 +2,7 @@
[![Build Status](https://travis-ci.org/jpush/jpush-phonegap-plugin.svg?branch=master)](https://travis-ci.org/jpush/jpush-phonegap-plugin)
[![QQ Group](https://img.shields.io/badge/QQ%20Group-413602425-red.svg)]()
[![release](https://img.shields.io/badge/release-2.2.7-blue.svg)](https://github.com/jpush/jpush-phonegap-plugin/releases)
[![release](https://img.shields.io/badge/release-3.0.1-blue.svg)](https://github.com/jpush/jpush-phonegap-plugin/releases)
[![platforms](https://img.shields.io/badge/platforms-iOS%7CAndroid-lightgrey.svg)](https://github.com/jpush/jpush-phonegap-plugin)
[![weibo](https://img.shields.io/badge/weibo-JPush-blue.svg)](http://weibo.com/jpush?refer_flag=1001030101_&is_all=1)

View File

@@ -1,5 +1,6 @@
# iOS API
- [延迟注册和启动推送通知服务](#延迟注册和启动推送通知服务)
- [开始与停止推送服务](#开始与停止推送服务)
- [获取 RegistrationID](#获取-registrationid)
- [别名与标签](#别名与标签)
@@ -19,6 +20,32 @@
- [获取用户推送设置](#获取用户推送设置)
- [监听事件统一说明](#监听事件统一说明)
## 延迟注册和启动推送通知服务
本插件默认在 App 启动完成之后,立即「注册苹果通知服务」+「启动 JPush SDK」其中
- 「注册苹果通知服务」会弹出提示窗口向用户请求权限。
- 「启动 JPush SDK」是使用 JPush 各项 API 的必要条件。
开发者可以根据自己的需求,延迟注册和启动,需做以下操作:
1. 查找并配置 `PushConfig.plist` 文件中的 `Delay` 字段为 `YES`,表明会延迟使用,此时插件不再自动注册、启动通知。
2. 在需要注册并启动通知的地方调用 API - startJPushSDK。
### API - startJPushSDK
注册苹果通知服务,并启动 JPush SDK。
#### 接口定义
```
window.plugins.jPushPlugin.startJPushSDK()
```
## 开始与停止推送服务
### API - init

View File

@@ -1,6 +1,6 @@
{
"name": "jpush-phonegap-plugin",
"version": "2.2.8",
"version": "3.0.2",
"description": "JPush for cordova plugin",
"cordova": {
"id": "jpush-phonegap-plugin",

View File

@@ -12,4 +12,5 @@
@interface AppDelegate (JPush) <JPUSHRegisterDelegate>
-(void)registerForRemoteNotification;
-(void)startJPushSDK;
@end

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"];

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";

View File

@@ -12,6 +12,9 @@
}
//注册通知服务并启动 SDK
-(void)startJPushSDK:(CDVInvokedUrlCommand*)command;
//以下为js中可调用接口
//设置标签、别名
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command;
@@ -78,7 +81,7 @@
@end
static JPushPlugin *SharedJPushPlugin;
JPushPlugin *SharedJPushPlugin;
@interface NSDictionary (JPush)
-(NSString*)toJsonString;

View File

@@ -1,3 +1,4 @@
//
// PushTalkPlugin.m
// PushTalk
@@ -38,6 +39,10 @@
@implementation JPushPlugin
-(void)startJPushSDK:(CDVInvokedUrlCommand*)command{
[(AppDelegate*)[UIApplication sharedApplication].delegate startJPushSDK];
}
#pragma mark-
-(void)stopPush:(CDVInvokedUrlCommand*)command{
[[UIApplication sharedApplication]unregisterForRemoteNotifications];
@@ -60,7 +65,7 @@
- (void)pluginInitialize {
NSLog(@"### pluginInitialize ");
SharedJPushPlugin = self;
[self initPlugin];
}
#else
@@ -69,11 +74,22 @@
NSLog(@"### initWithWebView ");
if (self=[super initWithWebView:theWebView]) {
}
[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]];

View File

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

View File

@@ -49,6 +49,11 @@ JPushPlugin.prototype.isPushStopped = function (callback) {
}
// iOS methods
JPushPlugin.prototype.startJPushSDK = function () {
this.call_native('startJPushSDK', [] , null)
}
JPushPlugin.prototype.setTagsWithAlias = function (tags, alias) {
if (tags == null) {
this.setAlias(alias)