mirror of
https://github.com/jpush/jpush-phonegap-plugin.git
synced 2026-04-19 00:03:45 +08:00
Compare commits
52 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b018a2748c | ||
|
|
39b7987b25 | ||
|
|
2c3bd5ab38 | ||
|
|
3e23fb9129 | ||
|
|
495497f3ac | ||
|
|
ca72c5eba1 | ||
|
|
4e687db4d3 | ||
|
|
3d74b92952 | ||
|
|
5a33f0c6e2 | ||
|
|
f80c4ca59c | ||
|
|
da08b93e43 | ||
|
|
9279611fcd | ||
|
|
3aec197d1d | ||
|
|
abd2a5bac9 | ||
|
|
360cdd4c95 | ||
|
|
9fbd45c7c7 | ||
|
|
894c2f902d | ||
|
|
70e2d6d9e2 | ||
|
|
ae42986fc9 | ||
|
|
1b2ffe13d8 | ||
|
|
1b0c64f235 | ||
|
|
219ae72758 | ||
|
|
9536989082 | ||
|
|
b1e00baeb8 | ||
|
|
e24a929ed3 | ||
|
|
2610f4ea9e | ||
|
|
aa53b5a214 | ||
|
|
acaff1c403 | ||
|
|
288253169a | ||
|
|
95587f9379 | ||
|
|
0eda4d42df | ||
|
|
206efc7b2c | ||
|
|
5c671fadc9 | ||
|
|
904384d8ae | ||
|
|
4215437bd6 | ||
|
|
8db89c9f2e | ||
|
|
992246235d | ||
|
|
8e0fee7276 | ||
|
|
734077536b | ||
|
|
bce9508ec5 | ||
|
|
ea685713db | ||
|
|
4c810fcaa9 | ||
|
|
213e5b7bb1 | ||
|
|
1af99fe4bf | ||
|
|
3e55f6f2c4 | ||
|
|
ec40fd3e58 | ||
|
|
e6819f54e2 | ||
|
|
386d1282e9 | ||
|
|
d55a46c54c | ||
|
|
bfe0a76ae0 | ||
|
|
7cc3239e1b | ||
|
|
34857a1eea |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.DS_Store
|
||||||
923
README.md
923
README.md
@@ -1,65 +1,93 @@
|
|||||||
## JPush PhoneGap Plugin ##
|
## JPush PhoneGap Plugin ##
|
||||||
###创建项目###
|
###创建项目###
|
||||||
1. cordova create 文件夹名字 包名 应用名字
|
1. cordova create 文件夹名字 包名 应用名字
|
||||||
```
|
|
||||||
cordova create Myproj com.myproj.jpush MyTestProj
|
|
||||||
```
|
|
||||||
|
|
||||||
|
cordova create Myproj com.myproj.jpush MyTestProj
|
||||||
|
|
||||||
2. 添加平台
|
2. 添加平台
|
||||||
```
|
|
||||||
cd Myproj :不进行这一步可能会出现[RangeError:Maximum call stack size exceeded]
|
|
||||||
cordova platform add android
|
|
||||||
```
|
|
||||||
|
|
||||||
### Android自动安装 ###
|
cd Myproj :不进入项目会出现[RangeError:Maximum call stack size exceeded]
|
||||||
|
cordova platform add android
|
||||||
|
cordova platform add ios
|
||||||
|
|
||||||
1. 使用 phonegap 或者 cordova cli 添加插件(建议在git客户端下使用,在windows 的cmd界面下 该命令提示git command line tool 不可用):
|
### Android使用PhoneGap/Cordova CLI自动安装
|
||||||
```
|
|
||||||
cordova plugin add https://github.com/jpush/jpush-phonegap-plugin.git
|
|
||||||
```
|
|
||||||
|
|
||||||
2. 修改www/config.xml文件,添加或者覆盖以下字段
|
1. 使用git命令将jpush phonegap插件下载的本地,将这个目录标记为`$JPUSH_PLUGIN_DIR`
|
||||||
|
|
||||||
|
git clone https://github.com/jpush/jpush-phonegap-plugin.git
|
||||||
|
|
||||||
|
2. 将`$JPUSH_PLUGIN_DIR/plugin.xml`文件中的AppKey替换为在Portal上注册该应用的的Key,例如(9fed5bcb7b9b87413678c407)
|
||||||
|
|
||||||
|
<meta-data android:name="JPUSH_APPKEY" android:value="your appkey"/>
|
||||||
|
|
||||||
####IOS使用PhoneGap/Cordova CLI自动安装
|
3. 在`$JPUSH_PLUGIN_DIR/src/android/JPushPlugin.java` 文件`import your.package.name.R`替换为在Portal上注册该应用的包名,例如(com.thi.pushtest)
|
||||||
|
|
||||||
1.使用PhoneGap/Cordova CLI命令安装
|
|
||||||
```
|
|
||||||
cordova plugin add https://github.com/zhangqinghe/test.phonegap.git
|
|
||||||
cordova platforms add ios
|
|
||||||
cordova build ios
|
|
||||||
```
|
|
||||||
|
|
||||||
2.修改Resources/PushConfig.plist文件
|
4. cordova cli 添加jpush phonegap插件和依赖的device插件:
|
||||||
```
|
|
||||||
|
cordova plugin add $JPUSH_PLUGIN_DIR
|
||||||
|
cordova plugin add org.apache.cordova.device
|
||||||
|
|
||||||
|
|
||||||
|
5. 在js中调用函数,初始化jpush sdk
|
||||||
|
|
||||||
|
window.plugins.jPushPlugin.init();
|
||||||
|
window.plugins.jPushPlugin.setDebugMode(true);
|
||||||
|
|
||||||
|
|
||||||
|
###IOS使用PhoneGap/Cordova CLI自动安装
|
||||||
|
|
||||||
|
1. 使用PhoneGap/Cordova CLI命令安装
|
||||||
|
|
||||||
|
cordova plugin add https://github.com/jpush/jpush-phonegap-plugin.git
|
||||||
|
cordova build ios
|
||||||
|
|
||||||
|
2. 修改Resources/PushConfig.plist文件
|
||||||
|
|
||||||
在APP_KEY和CHANNLE字段 分别添加您的appkey和channle
|
在APP_KEY和CHANNLE字段 分别添加您的appkey和channle
|
||||||
```
|
|
||||||
3.添加监听系统事件,相应地调用 JPush SDK 提供的 API 来实现功能
|
|
||||||
```
|
|
||||||
|
|
||||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
3. 添加监听系统事件,相应地调用 JPush SDK 提供的 API 来实现功能
|
||||||
{
|
|
||||||
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
|
|
||||||
self.window.backgroundColor = [UIColor whiteColor];
|
|
||||||
[self.window makeKeyAndVisible];
|
|
||||||
// Required
|
|
||||||
[APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
|
|
||||||
UIRemoteNotificationTypeSound |
|
|
||||||
UIRemoteNotificationTypeAlert)];
|
|
||||||
// Required
|
|
||||||
[APService setupWithOption:launchOptions];
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
|
|
||||||
// Required
|
|
||||||
[APService registerDeviceToken:deviceToken];
|
|
||||||
}
|
|
||||||
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
|
|
||||||
// Required
|
|
||||||
[APService handleRemoteNotification:userInfo];
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
|
||||||
|
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
|
||||||
|
self.window.backgroundColor = [UIColor whiteColor];
|
||||||
|
[self.window makeKeyAndVisible];
|
||||||
|
// Required
|
||||||
|
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1
|
||||||
|
if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
|
||||||
|
//可以添加自定义categories
|
||||||
|
[APService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
|
||||||
|
UIUserNotificationTypeSound |
|
||||||
|
UIUserNotificationTypeAlert)
|
||||||
|
categories:nil];
|
||||||
|
} else {
|
||||||
|
//categories 必须为nil
|
||||||
|
[APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
|
||||||
|
UIRemoteNotificationTypeSound |
|
||||||
|
UIRemoteNotificationTypeAlert)
|
||||||
|
categories:nil];
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
//categories 必须为nil
|
||||||
|
[APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
|
||||||
|
UIRemoteNotificationTypeSound |
|
||||||
|
UIRemoteNotificationTypeAlert)
|
||||||
|
categories:nil];
|
||||||
|
#endif
|
||||||
|
// Required
|
||||||
|
[APService setupWithOption:launchOptions];
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
|
||||||
|
// Required
|
||||||
|
[APService registerDeviceToken:deviceToken];
|
||||||
|
}
|
||||||
|
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
|
||||||
|
// Required
|
||||||
|
[APService handleRemoteNotification:userInfo];
|
||||||
|
}
|
||||||
|
|
||||||
###Android 手工安装###
|
###Android 手工安装###
|
||||||
1. 复制src/android/*.java 到cn/jpush/phonega/目录下(即:cn.jpush.phonegap的包下)
|
1. 复制src/android/*.java 到cn/jpush/phonega/目录下(即:cn.jpush.phonegap的包下)
|
||||||
2. 复制src/android/armeabi/libjpush.so 到lib/armeabi/
|
2. 复制src/android/armeabi/libjpush.so 到lib/armeabi/
|
||||||
@@ -68,188 +96,661 @@ cordova build ios
|
|||||||
5. 复制src/android/jpush_notification_icon.png 到res/drawable/
|
5. 复制src/android/jpush_notification_icon.png 到res/drawable/
|
||||||
6. 修改 AndroidManifest.xml 在 manifest 节点下添加以下权限
|
6. 修改 AndroidManifest.xml 在 manifest 节点下添加以下权限
|
||||||
|
|
||||||
```
|
<!-- Required 一些系统要求的权限,如访问网络等-->
|
||||||
<!-- Required 一些系统要求的权限,如访问网络等-->
|
<uses-permission android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE"/>
|
||||||
<uses-permission android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE"/>
|
<uses-permission android:name="android.permission.RECEIVE_USER_PRESENT"/>
|
||||||
<uses-permission android:name="android.permission.RECEIVE_USER_PRESENT"/>
|
<uses-permission android:name="android.permission.INTERNET"/>
|
||||||
<uses-permission android:name="android.permission.INTERNET"/>
|
<uses-permission android:name="android.permission.WAKE_LOCK"/>
|
||||||
<uses-permission android:name="android.permission.WAKE_LOCK"/>
|
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
|
||||||
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
||||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
<uses-permission android:name="android.permission.VIBRATE"/>
|
||||||
<uses-permission android:name="android.permission.VIBRATE"/>
|
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
|
||||||
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
|
||||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
|
<permission
|
||||||
<permission
|
android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE"
|
||||||
android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE"
|
android:protectionLevel="signature"/>
|
||||||
android:protectionLevel="signature"/>
|
|
||||||
```
|
|
||||||
7. 修改AndroidManifest.xml 在 manifest/application 节点下添加SDK相关组件声明
|
7. 修改AndroidManifest.xml 在 manifest/application 节点下添加SDK相关组件声明
|
||||||
|
|
||||||
```
|
<activity
|
||||||
<activity
|
android:name="cn.jpush.android.ui.PushActivity"
|
||||||
android:name="cn.jpush.android.ui.PushActivity"
|
android:theme="@android:style/Theme.Translucent.NoTitleBar"
|
||||||
android:theme="@android:style/Theme.Translucent.NoTitleBar"
|
android:configChanges="orientation|keyboardHidden">
|
||||||
android:configChanges="orientation|keyboardHidden">
|
<intent-filter>
|
||||||
<intent-filter>
|
<action android:name="cn.jpush.android.ui.PushActivity"/>
|
||||||
<action android:name="cn.jpush.android.ui.PushActivity"/>
|
<category android:name="android.intent.category.DEFAULT"/>
|
||||||
<category android:name="android.intent.category.DEFAULT"/>
|
<category android:name="$PACKAGE_NAME"/>
|
||||||
<category android:name="$PACKAGE_NAME"/>
|
</intent-filter>
|
||||||
</intent-filter>
|
</activity>
|
||||||
</activity>
|
<!-- Required SDK核心功能-->
|
||||||
<!-- Required SDK核心功能-->
|
<service
|
||||||
<service
|
android:name="cn.jpush.android.service.DownloadService"
|
||||||
android:name="cn.jpush.android.service.DownloadService"
|
android:enabled="true"
|
||||||
android:enabled="true"
|
android:exported="false">
|
||||||
android:exported="false">
|
</service>
|
||||||
</service>
|
<!-- Required SDK 核心功能-->
|
||||||
<!-- Required SDK 核心功能-->
|
<service
|
||||||
<service
|
android:name="cn.jpush.android.service.PushService"
|
||||||
android:name="cn.jpush.android.service.PushService"
|
android:enabled="true"
|
||||||
android:enabled="true"
|
android:exported="false">
|
||||||
android:exported="false">
|
<intent-filter>
|
||||||
<intent-filter>
|
<action android:name="cn.jpush.android.intent.REGISTER"/>
|
||||||
<action android:name="cn.jpush.android.intent.REGISTER"/>
|
<action android:name="cn.jpush.android.intent.REPORT"/>
|
||||||
<action android:name="cn.jpush.android.intent.REPORT"/>
|
<action android:name="cn.jpush.android.intent.PushService"/>
|
||||||
<action android:name="cn.jpush.android.intent.PushService"/>
|
<action android:name="cn.jpush.android.intent.PUSH_TIME"/>
|
||||||
<action android:name="cn.jpush.android.intent.PUSH_TIME"/>
|
|
||||||
|
</intent-filter>
|
||||||
|
</service>
|
||||||
|
<!-- Required SDK核心功能-->
|
||||||
|
<receiver
|
||||||
|
android:name="cn.jpush.android.service.PushReceiver"
|
||||||
|
android:enabled="true">
|
||||||
|
<intent-filter android:priority="1000">
|
||||||
|
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY"/>
|
||||||
|
<!--Required 显示通知栏 -->
|
||||||
|
<category android:name="$PACKAGE_NAME"/>
|
||||||
|
</intent-filter>
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.USER_PRESENT"/>
|
||||||
|
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
|
||||||
|
</intent-filter>
|
||||||
|
<!-- Optional -->
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.PACKAGE_ADDED"/>
|
||||||
|
<action android:name="android.intent.action.PACKAGE_REMOVED"/>
|
||||||
|
<data android:scheme="package"/>
|
||||||
|
</intent-filter>
|
||||||
|
</receiver>
|
||||||
|
|
||||||
|
<!-- User defined. For test only 用户自定义的广播接收器 -->
|
||||||
|
<receiver
|
||||||
|
android:name="cn.jpush.phonegap.MyReceiver"
|
||||||
|
android:enabled="true">
|
||||||
|
<intent-filter android:priority="1000">
|
||||||
|
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY"/>
|
||||||
|
<!-- Required 显示通知栏 -->
|
||||||
|
<category android:name="$PACKAGE_NAME"/>
|
||||||
|
</intent-filter>
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="cn.jpush.android.intent.REGISTRATION"/>
|
||||||
|
<!-- Required 用户注册SDK的intent -->
|
||||||
|
<action android:name="cn.jpush.android.intent.UNREGISTRATION"/>
|
||||||
|
<action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED"/>
|
||||||
|
<!-- Required 用户接收SDK消息的intent -->
|
||||||
|
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED"/>
|
||||||
|
<!-- Required 用户接收SDK通知栏信息的intent -->
|
||||||
|
<action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED"/>
|
||||||
|
<!-- Required 用户打开自定义通知栏的intent -->
|
||||||
|
<action android:name="cn.jpush.android.intent.ACTION_RICHPUSH_CALLBACK"/>
|
||||||
|
<!-- Optional 用户接受Rich Push Javascript 回调函数的intent -->
|
||||||
|
<category android:name="$PACKAGE_NAME"/>
|
||||||
|
</intent-filter>
|
||||||
|
</receiver>
|
||||||
|
<!-- Required SDK核心功能-->
|
||||||
|
<receiver android:name="cn.jpush.android.service.AlarmReceiver"/>
|
||||||
|
<!-- Required . Enable it you can get statistics data with channel -->
|
||||||
|
<meta-data android:name="JPUSH_CHANNEL" android:value="developer-default"/>
|
||||||
|
<meta-data android:name="JPUSH_APPKEY" android:value="299d0fee887820e7d90a68b2"/>
|
||||||
|
|
||||||
</intent-filter>
|
|
||||||
</service>
|
|
||||||
<!-- Required SDK核心功能-->
|
|
||||||
<receiver
|
|
||||||
android:name="cn.jpush.android.service.PushReceiver"
|
|
||||||
android:enabled="true">
|
|
||||||
<intent-filter android:priority="1000">
|
|
||||||
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY"/>
|
|
||||||
<!--Required 显示通知栏 -->
|
|
||||||
<category android:name="$PACKAGE_NAME"/>
|
|
||||||
</intent-filter>
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.USER_PRESENT"/>
|
|
||||||
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
|
|
||||||
</intent-filter>
|
|
||||||
<!-- Optional -->
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.PACKAGE_ADDED"/>
|
|
||||||
<action android:name="android.intent.action.PACKAGE_REMOVED"/>
|
|
||||||
<data android:scheme="package"/>
|
|
||||||
</intent-filter>
|
|
||||||
</receiver>
|
|
||||||
|
|
||||||
<!-- User defined. For test only 用户自定义的广播接收器 -->
|
|
||||||
<receiver
|
|
||||||
android:name="cn.jpush.phonegap.MyReceiver"
|
|
||||||
android:enabled="true">
|
|
||||||
<intent-filter android:priority="1000">
|
|
||||||
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY"/>
|
|
||||||
<!-- Required 显示通知栏 -->
|
|
||||||
<category android:name="$PACKAGE_NAME"/>
|
|
||||||
</intent-filter>
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="cn.jpush.android.intent.REGISTRATION"/>
|
|
||||||
<!-- Required 用户注册SDK的intent -->
|
|
||||||
<action android:name="cn.jpush.android.intent.UNREGISTRATION"/>
|
|
||||||
<action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED"/>
|
|
||||||
<!-- Required 用户接收SDK消息的intent -->
|
|
||||||
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED"/>
|
|
||||||
<!-- Required 用户接收SDK通知栏信息的intent -->
|
|
||||||
<action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED"/>
|
|
||||||
<!-- Required 用户打开自定义通知栏的intent -->
|
|
||||||
<action android:name="cn.jpush.android.intent.ACTION_RICHPUSH_CALLBACK"/>
|
|
||||||
<!-- Optional 用户接受Rich Push Javascript 回调函数的intent -->
|
|
||||||
<category android:name="$PACKAGE_NAME"/>
|
|
||||||
</intent-filter>
|
|
||||||
</receiver>
|
|
||||||
<!-- Required SDK核心功能-->
|
|
||||||
<receiver android:name="cn.jpush.android.service.AlarmReceiver"/>
|
|
||||||
<!-- Required . Enable it you can get statistics data with channel -->
|
|
||||||
<meta-data android:name="JPUSH_CHANNEL" android:value="developer-default"/>
|
|
||||||
<meta-data android:name="JPUSH_APPKEY" android:value="299d0fee887820e7d90a68b2"/>
|
|
||||||
|
|
||||||
```
|
|
||||||
### IOS手工安装
|
### IOS手工安装
|
||||||
|
|
||||||
1.添加src/ios/Plugins/到project中
|
1. 添加src/ios/Plugins/到project中
|
||||||
2.添加src/ios/lib/到project中
|
2. 添加src/ios/lib/到project中
|
||||||
3.设置 Search Paths 下的 User Header Search Paths 和 Library Search Paths
|
3. 设置 Search Paths 下的 User Header Search Paths 和 Library Search Paths
|
||||||
```
|
|
||||||
|
|
||||||
比如SDK文件夹(默认为lib)与工程文件在同一级目录下,则都设置为"$(SRCROOT)/[文件夹名称]"即可。
|
比如SDK文件夹(默认为lib)与工程文件在同一级目录下,则都设置为"$(SRCROOT)/[文件夹名称]"即可。
|
||||||
```
|
|
||||||
|
|
||||||
4.确认一下的框架是存在的(Target -> Build Phases -> Link Binary With Libraries)
|
4. 确认一下的框架是存在的(Target -> Build Phases -> Link Binary With Libraries)
|
||||||
```
|
|
||||||
|
|
||||||
CFNetwork.framework
|
CFNetwork.framework
|
||||||
CoreFoundation.framework
|
CoreFoundation.framework
|
||||||
CoreTelephony.framework
|
CoreTelephony.framework
|
||||||
SystemConfiguration.framework
|
SystemConfiguration.framework
|
||||||
CoreGraphics.framework
|
CoreGraphics.framework
|
||||||
Foundation.framework
|
Foundation.framework
|
||||||
UIKit.framework
|
UIKit.framework
|
||||||
```
|
|
||||||
|
|
||||||
5.在你的工程中创建一个新的Property List文件
|
|
||||||
```
|
|
||||||
|
|
||||||
并将其命名为PushConfig.plist,填入Portal为你的应用提供的APP_KEY等参数
|
5. 在你的工程中创建一个新的Property List文件
|
||||||
```
|
|
||||||
|
|
||||||
6.调用代码,监听系统事件,相应地调用 JPush SDK 提供的 API 来实现功能
|
并将其命名为PushConfig.plist,填入Portal为你的应用提供的APP_KEY等参数
|
||||||
```
|
|
||||||
|
|
||||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
|
||||||
{
|
|
||||||
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
|
|
||||||
self.window.backgroundColor = [UIColor whiteColor];
|
|
||||||
[self.window makeKeyAndVisible];
|
|
||||||
|
|
||||||
// Required
|
|
||||||
[APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
|
|
||||||
UIRemoteNotificationTypeSound |
|
|
||||||
UIRemoteNotificationTypeAlert)];
|
|
||||||
// Required
|
|
||||||
[APService setupWithOption:launchOptions];
|
|
||||||
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
|
|
||||||
|
|
||||||
// Required
|
|
||||||
[APService registerDeviceToken:deviceToken];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
|
|
||||||
|
|
||||||
// Required
|
|
||||||
[APService handleRemoteNotification:userInfo];
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
7.修改phonegap config.xml文件用来包含Plugin/内的插件
|
6. 调用代码,监听系统事件,相应地调用 JPush SDK 提供的 API 来实现功能
|
||||||
```
|
|
||||||
|
|
||||||
<feature name="JPushPlugin">
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
||||||
<param name="ios-package" value="JPushPlugin" />
|
{
|
||||||
<param name="onload" value="true" />
|
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
|
||||||
</feature>
|
self.window.backgroundColor = [UIColor whiteColor];
|
||||||
```
|
[self.window makeKeyAndVisible];
|
||||||
|
|
||||||
|
// Required
|
||||||
|
[APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
|
||||||
|
UIRemoteNotificationTypeSound |
|
||||||
|
UIRemoteNotificationTypeAlert)];
|
||||||
|
// Required
|
||||||
|
[APService setupWithOption:launchOptions];
|
||||||
|
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
|
||||||
|
|
||||||
|
// Required
|
||||||
|
[APService registerDeviceToken:deviceToken];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
|
||||||
|
|
||||||
|
// Required
|
||||||
|
[APService handleRemoteNotification:userInfo];
|
||||||
|
}
|
||||||
|
|
||||||
8.复制www/PushNotification.js到工程的www目录下面
|
|
||||||
9.在需要使用插件处加入
|
|
||||||
```
|
|
||||||
|
|
||||||
<script type="text/javascript" src="JPushPlugin.js"></script>
|
7. 修改phonegap config.xml文件用来包含Plugin/内的插件
|
||||||
```
|
|
||||||
|
|
||||||
|
<feature name="JPushPlugin">
|
||||||
|
<param name="ios-package" value="JPushPlugin" />
|
||||||
|
<param name="onload" value="true" />
|
||||||
|
</feature>
|
||||||
|
|
||||||
|
|
||||||
|
8. 复制www/PushNotification.js到工程的www目录下面
|
||||||
|
9. 在需要使用插件处加入
|
||||||
|
|
||||||
|
<script type="text/javascript" src="JPushPlugin.js"></script>
|
||||||
|
|
||||||
###示例
|
###示例
|
||||||
1.完整的示例可以点击网页右侧的"Download Zip"下载,下载完成后在文件的"src/ios/example"文件夹内找到并拷贝以下文件
|
|
||||||
```
|
|
||||||
|
|
||||||
src/ios/example/index.html to www/index.html
|
1. 完整的示例可以点击网页右侧的"Download Zip"下载,下载完成后在文件的"src/ios/example"文件夹内找到并拷贝以下文件
|
||||||
src/ios/example/css/* to www/css
|
|
||||||
src/ios/example/js/* to www/js
|
src/ios/example/index.html to www/index.html
|
||||||
```
|
src/ios/example/css/* to www/css
|
||||||
|
src/ios/example/js/* to www/js
|
||||||
|
|
||||||
|
###关于'phonegap build'云服务
|
||||||
|
该项目基于cordova实现,目前无法使用'phonegap build'云服务进行打包,建议使用本地环境进行打包
|
||||||
|
###常见错误
|
||||||
|
1. androd
|
||||||
|
|
||||||
|
eclipse中phonegap工程import之后出现:`Type CallbackContext cannot be resolved to a type`
|
||||||
|
解决方案:eclipse中右键单击工程名,Build Path->Config Build Path->Projects->选中 工程名称-CordovaLib->点击 add
|
||||||
|
|
||||||
|
### API说明
|
||||||
|
|
||||||
|
插件的API集中在JPushPlugin.js文件中,这个文件的位置如下
|
||||||
|
|
||||||
|
* android:[YOUR__ANDROID_PROJECT]/assets/www/plugins/cn.jpush.phonegap.JPushPlugin/www
|
||||||
|
* iOS:[YOUR_iOS_PROJEcT]/www/plugins/cn.jpush.phonegap.JPushPlugin/www
|
||||||
|
|
||||||
|
这里只说明public的函数
|
||||||
|
|
||||||
|
|
||||||
|
#### API - setTagsWithAlias,setTags,setAlias
|
||||||
|
|
||||||
|
提供几个相关 API 用来设置别名(alias)与标签(tags)。
|
||||||
|
|
||||||
|
这几个 API 可以在 App 里任何地方调用。
|
||||||
|
|
||||||
|
别名 alias
|
||||||
|
|
||||||
|
为安装了应用程序的用户,取个别名来标识。以后给该用户 Push 消息时,就可以用此别名来指定。
|
||||||
|
|
||||||
|
每个用户只能指定一个别名。
|
||||||
|
|
||||||
|
同一个应用程序内,对不同的用户,建议取不同的别名。这样,尽可能根据别名来唯一确定用户。
|
||||||
|
|
||||||
|
系统不限定一个别名只能指定一个用户。如果一个别名被指定到了多个用户,当给指定这个别名发消息时,服务器端API会同时给这多个用户发送消息。
|
||||||
|
|
||||||
|
举例:在一个用户要登录的游戏中,可能设置别名为 userid。游戏运营时,发现该用户 3 天没有玩游戏了,则根据 userid 调用服务器端API发通知到客户端提醒用户。
|
||||||
|
|
||||||
|
标签 tag
|
||||||
|
|
||||||
|
为安装了应用程序的用户,打上标签。其目的主要是方便开发者根据标签,来批量下发 Push 消息。
|
||||||
|
|
||||||
|
可为每个用户打多个标签。
|
||||||
|
|
||||||
|
不同应用程序、不同的用户,可以打同样的标签。
|
||||||
|
|
||||||
|
举例: game, old_page, women
|
||||||
|
|
||||||
|
##### 接口定义
|
||||||
|
|
||||||
|
JPushPlugin.prototype.setTagsWithAlias = function(tags,alias)
|
||||||
|
JPushPlugin.prototype.setTags = function(tags)
|
||||||
|
JPushPlugin.prototype.setAlias = function(alias)
|
||||||
|
|
||||||
|
#####使用平台
|
||||||
|
android iOS
|
||||||
|
|
||||||
|
|
||||||
|
##### 参数说明
|
||||||
|
* tags
|
||||||
|
* 参数类型为数组
|
||||||
|
* nil 此次调用不设置此值
|
||||||
|
* 空集合表示取消之前的设置
|
||||||
|
* 每次调用至少设置一个 tag,覆盖之前的设置,不是新增
|
||||||
|
* 有效的标签组成:字母(区分大小写)、数字、下划线、汉字
|
||||||
|
* 限制:每个 tag 命名长度限制为 40 字节,最多支持设置 100 个 tag,但总长度不得超过1K字节。(判断长度需采用UTF-8编码)
|
||||||
|
* 单个设备最多支持设置 100 个 tag。App 全局 tag 数量无限制。
|
||||||
|
* alias
|
||||||
|
* 参数类型为字符串
|
||||||
|
* nil 此次调用不设置此值
|
||||||
|
* 空字符串 ("")表示取消之前的设置
|
||||||
|
* 有效的别名组成:字母(区分大小写)、数字、下划线、汉字。
|
||||||
|
* 限制:alias 命名长度限制为 40 字节。(判断长度需采用UTF-8编码)
|
||||||
|
|
||||||
|
##### 返回值说明
|
||||||
|
|
||||||
|
函数本身无返回值,但需要注册`jpush.setTagsWithAlias `事件来监听设置结果
|
||||||
|
|
||||||
|
document.addEventListener("jpush.setTagsWithAlias", onTagsWithAlias, false);
|
||||||
|
var onTagsWithAlias = function(event){
|
||||||
|
try{
|
||||||
|
console.log("onTagsWithAlias");
|
||||||
|
var result="result code:"+event.resultCode+" ";
|
||||||
|
result+="tags:"+event.tags+" ";
|
||||||
|
result+="alias:"+event.alias+" ";
|
||||||
|
$("#tagAliasResult").html(result);
|
||||||
|
}
|
||||||
|
catch(exception){
|
||||||
|
console.log(exception)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#####错误码定义
|
||||||
|
|
||||||
|
|
||||||
|
|Code|描述|详细解释|
|
||||||
|
|-|-|-|
|
||||||
|
|6001| 无效的设置,tag/alias 不应参数都为 null||
|
||||||
|
|6002| 设置超时| 建议重试|
|
||||||
|
|6003| alias| 字符串不合法 有效的别名、标签组成:字母(区分大小写)、数字、下划线、汉字。|
|
||||||
|
|6004| alias超长。最多 40个字节 中文 UTF-8 是 3 个字节|
|
||||||
|
|6005| 某一个 tag 字符串不合法| 有效的别名、标签组成:字母(区分大小写)、数字、下划线、汉字。|
|
||||||
|
|6006| 某一个 tag 超长。|一个 tag 最多 40个字节 中文 UTF-8 是 3 个字节|
|
||||||
|
|6007| tags 数量超出限制。最多 100个| 这是一台设备的限制。一个应用全局的标签数量无限制。|
|
||||||
|
|6008| tag/alias 超出总长度限制。|总长度最多 1K 字节|
|
||||||
|
|6011| 10s内设置tag或alias大于3次| 短时间内操作过于频繁|
|
||||||
|
|
||||||
|
|
||||||
|
#### API - startLogPageView,stopLogPageView,beginLogPageView
|
||||||
|
|
||||||
|
本 API 用于“用户指定页面使用时长”的统计,并上报到服务器,在 Portal 上展示给开发者。页面统计集成正确,才能够获取正确的页面访问路径、访问深度(PV)的数据。
|
||||||
|
|
||||||
|
##### 接口定义
|
||||||
|
JPushPlugin.prototype.startLogPageView = function(pageName)
|
||||||
|
JPushPlugin.prototype.stopLogPageView = function(pageName)
|
||||||
|
JPushPlugin.prototype.beginLogPageView = function(pageName,duration)
|
||||||
|
|
||||||
|
#####平台
|
||||||
|
iOS
|
||||||
|
|
||||||
|
#####参数说明
|
||||||
|
pageName 需要统计页面自定义名称
|
||||||
|
duration 自定义的页面时间
|
||||||
|
|
||||||
|
#####调用说明
|
||||||
|
应在所有的需要统计得页面得 viewWillAppear 和 viewWillDisappear 加入 startLogPageView 和 stopLogPageView 来统计当前页面的停留时间。
|
||||||
|
|
||||||
|
或者直接使用 beginLogPageView 来自定义加入页面和时间信息。
|
||||||
|
|
||||||
|
|
||||||
|
#####返回值说明
|
||||||
|
无
|
||||||
|
|
||||||
|
#####代码示例
|
||||||
|
|
||||||
|
if(window.plugins.jPushPlugin.isPlatformIOS()){
|
||||||
|
window.plugins.jPushPlugin.beginLogPageView("newPage",5);
|
||||||
|
window.plugins.jPushPlugin.startLogPageView("onePage");
|
||||||
|
window.plugins.jPushPlugin.stopLogPageView("onePage");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### API - setBadge,resetBadge
|
||||||
|
|
||||||
|
badge是iOS用来标记应用程序状态的一个数字,出现在程序图标右上角。 JPush封装badge功能,允许应用上传badge值至JPush服务器,由JPush后台帮助管理每个用户所对应的推送badge值,简化了设置推送badge的操作。
|
||||||
|
|
||||||
|
实际应用中,开发者可以直接对badge值做增减操作,无需自己维护用户与badge值之间的对应关系。
|
||||||
|
|
||||||
|
##### 接口定义
|
||||||
|
|
||||||
|
JPushPlugin.prototype.setBadge = function(value)
|
||||||
|
JPushPlugin.prototype.resetBadge = function()
|
||||||
|
|
||||||
|
`resetBadge相当于setBadge(0)`
|
||||||
|
|
||||||
|
##### 平台
|
||||||
|
iOS
|
||||||
|
|
||||||
|
##### 参数说明
|
||||||
|
|
||||||
|
value 取值范围:[0,99999]
|
||||||
|
|
||||||
|
##### 返回值
|
||||||
|
|
||||||
|
无,控制台会有log打印设置结果
|
||||||
|
|
||||||
|
|
||||||
|
#####代码示例
|
||||||
|
|
||||||
|
if(window.plugins.jPushPlugin.isPlatformIOS()){
|
||||||
|
window.plugins.jPushPlugin.setBadge(5);
|
||||||
|
window.plugins.jPushPlugin.reSetBadge();
|
||||||
|
}
|
||||||
|
#### API - setDebugModeFromIos
|
||||||
|
|
||||||
|
API 用于开启Debug模式,显示更多的日志信息
|
||||||
|
|
||||||
|
建议调试时开启这个选项,不调试的时候注释这句代码,这个函数setLogOFF是相反的一对
|
||||||
|
|
||||||
|
##### 接口定义
|
||||||
|
|
||||||
|
JPushPlugin.prototype.setDebugModeFromIos = function()
|
||||||
|
|
||||||
|
##### 平台
|
||||||
|
iOS
|
||||||
|
|
||||||
|
#####代码示例
|
||||||
|
|
||||||
|
if(window.plugins.jPushPlugin.isPlatformIOS()){
|
||||||
|
window.plugins.jPushPlugin.setDebugModeFromIos();
|
||||||
|
}
|
||||||
|
|
||||||
|
#### API - setLogOFF
|
||||||
|
|
||||||
|
API用来关闭日志信息(除了必要的错误信息)
|
||||||
|
|
||||||
|
不需要任何调试信息的时候,调用此API (发布时建议调用此API,用来屏蔽日志信息,节省性能消耗)
|
||||||
|
|
||||||
|
##### 平台
|
||||||
|
iOS
|
||||||
|
|
||||||
|
##### 接口定义
|
||||||
|
|
||||||
|
JPushPlugin.prototype.setLogOFF = function()
|
||||||
|
|
||||||
|
#####代码示例
|
||||||
|
|
||||||
|
if(window.plugins.jPushPlugin.isPlatformIOS()){
|
||||||
|
window.plugins.jPushPlugin.setLogOFF();
|
||||||
|
}
|
||||||
|
|
||||||
|
#### API - receiveMessageIniOSCallback
|
||||||
|
|
||||||
|
用于iOS收到应用内消息的回调函数(请注意和通知的区别),该函数不需要主动调用
|
||||||
|
|
||||||
|
##### 使用平台
|
||||||
|
iOS
|
||||||
|
|
||||||
|
##### 参数说明
|
||||||
|
|
||||||
|
- data 是一个js字符串使用如下代码解析,js具体key根据应用内消息来确定
|
||||||
|
|
||||||
|
var bToObj = JSON.parse(data);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### API - init
|
||||||
|
|
||||||
|
调用此API,用来
|
||||||
|
JPush SDK 提供的推送服务是默认开启的。
|
||||||
|
|
||||||
|
|
||||||
|
##### 接口定义
|
||||||
|
|
||||||
|
JPushPlugin.prototype.init = function()
|
||||||
|
|
||||||
|
##### 参数说明
|
||||||
|
无
|
||||||
|
##### 返回值
|
||||||
|
无
|
||||||
|
|
||||||
|
|
||||||
|
#### API - setDebugMode
|
||||||
|
|
||||||
|
用于开启调试模式,可以查看集成JPush过程中的log,如果集成失败,可方便定位问题所在
|
||||||
|
|
||||||
|
##### 接口定义
|
||||||
|
|
||||||
|
JPushPlugin.prototype.setDebugMode = function(mode)
|
||||||
|
|
||||||
|
##### 参数说明
|
||||||
|
|
||||||
|
- num 保存的条数
|
||||||
|
|
||||||
|
##### 返回值
|
||||||
|
无
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### API - stopPush
|
||||||
|
|
||||||
|
|
||||||
|
开发者App可以通过调用停止推送服务API来停止极光推送服务。当又需要使用极光推送服务时,则必须要调用恢复推送服务 API。
|
||||||
|
|
||||||
|
调用了本 API 后,JPush 推送服务完全被停止。具体表现为:
|
||||||
|
|
||||||
|
- JPush Service 不在后台运行
|
||||||
|
- 收不到推送消息
|
||||||
|
- 不能通过 JPushInterface.init 恢复,需要调用resumePush恢复
|
||||||
|
- 极光推送所有的其他 API 调用都无效
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
##### 接口定义
|
||||||
|
|
||||||
|
JPushPlugin.prototype.stopPush = function()
|
||||||
|
|
||||||
|
#####平台
|
||||||
|
android
|
||||||
|
|
||||||
|
|
||||||
|
##### 参数说明
|
||||||
|
无
|
||||||
|
##### 返回值
|
||||||
|
无
|
||||||
|
|
||||||
|
#### API - resumePush
|
||||||
|
|
||||||
|
恢复推送服务。
|
||||||
|
调用了此 API 后,极光推送完全恢复正常工作。
|
||||||
|
|
||||||
|
##### 接口定义
|
||||||
|
|
||||||
|
JPushPlugin.prototype.resumePush = function()
|
||||||
|
|
||||||
|
##### 参数说明
|
||||||
|
无
|
||||||
|
##### 返回值
|
||||||
|
无
|
||||||
|
|
||||||
|
#### API - isPushStopped
|
||||||
|
|
||||||
|
用来检查 Push Service 是否已经被停止
|
||||||
|
|
||||||
|
##### 接口定义
|
||||||
|
|
||||||
|
JPushPlugin.prototype.isPushStopped = function(callback)
|
||||||
|
|
||||||
|
|
||||||
|
#####平台
|
||||||
|
android
|
||||||
|
|
||||||
|
##### 参数说明
|
||||||
|
|
||||||
|
+ callback 回调函数,用来通知JPush的推送服务是否开启
|
||||||
|
|
||||||
|
var onCallback = function(data) {
|
||||||
|
if(data>0){
|
||||||
|
//开启
|
||||||
|
}else{
|
||||||
|
//关闭
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
##### 返回值
|
||||||
|
无
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### API - setBasicPushNotificationBuilder,setCustomPushNotificationBuilder
|
||||||
|
|
||||||
|
当用户需要定制默认的通知栏样式时,则可调用此方法。
|
||||||
|
极光 Push SDK 提供了 2 个用于定制通知栏样式的构建类:
|
||||||
|
|
||||||
|
- setBasicPushNotificationBuilder
|
||||||
|
- Basic 用于定制 Android Notification 里的 defaults / flags / icon 等基础样式(行为)
|
||||||
|
- setCustomPushNotificationBuilder
|
||||||
|
- 继承 Basic 进一步让开发者定制 Notification Layout
|
||||||
|
|
||||||
|
如果不调用此方法定制,则极光Push SDK 默认的通知栏样式是:Android标准的通知栏提示。
|
||||||
|
|
||||||
|
#####平台
|
||||||
|
android
|
||||||
|
|
||||||
|
##### 接口定义
|
||||||
|
|
||||||
|
JPushPlugin.prototype.setBasicPushNotificationBuilder = function()
|
||||||
|
JPushPlugin.prototype.setCustomPushNotificationBuilder = function()
|
||||||
|
|
||||||
|
#### 参数说明
|
||||||
|
|
||||||
|
无
|
||||||
|
|
||||||
|
##### 返回值
|
||||||
|
|
||||||
|
无
|
||||||
|
|
||||||
|
#### API - clearAllNotification
|
||||||
|
|
||||||
|
推送通知到客户端时,由 JPush SDK 展现通知到通知栏上。
|
||||||
|
|
||||||
|
此 API 提供清除通知的功能,包括:清除所有 JPush 展现的通知(不包括非 JPush SDK 展现的)
|
||||||
|
|
||||||
|
|
||||||
|
##### 接口定义
|
||||||
|
|
||||||
|
JPushPlugin.prototype.clearAllNotification = function()
|
||||||
|
|
||||||
|
#####平台
|
||||||
|
android
|
||||||
|
|
||||||
|
##### 参数说明
|
||||||
|
无
|
||||||
|
##### 返回值
|
||||||
|
无
|
||||||
|
|
||||||
|
#### API - setLatestNotificationNum
|
||||||
|
|
||||||
|
通过极光推送,推送了很多通知到客户端时,如果用户不去处理,就会有很多保留在那里。
|
||||||
|
|
||||||
|
新版本 SDK (v1.3.0) 增加此功能,限制保留的通知条数。默认为保留最近 5 条通知。
|
||||||
|
|
||||||
|
开发者可通过调用此 API 来定义为不同的数量。
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
##### 接口定义
|
||||||
|
|
||||||
|
JPushPlugin.prototype.setLatestNotificationNum = function(num)
|
||||||
|
|
||||||
|
|
||||||
|
#####平台
|
||||||
|
android
|
||||||
|
|
||||||
|
##### 参数说明
|
||||||
|
|
||||||
|
- num 保存的条数
|
||||||
|
|
||||||
|
##### 返回值
|
||||||
|
无
|
||||||
|
|
||||||
|
|
||||||
|
#### API - addLocalNotification,removeLocalNotification,clearLocalNotifications
|
||||||
|
|
||||||
|
|
||||||
|
本地通知API不依赖于网络,无网条件下依旧可以触发
|
||||||
|
|
||||||
|
本地通知与网络推送的通知是相互独立的,不受保留最近通知条数上限的限制
|
||||||
|
|
||||||
|
本地通知的定时时间是自发送时算起的,不受中间关机等操作的影响
|
||||||
|
|
||||||
|
|
||||||
|
三个接口的功能分别为:添加一个本地通知,删除一个本地通知,删除所有的本地通知
|
||||||
|
|
||||||
|
#####接口定义
|
||||||
|
|
||||||
|
JPushPlugin.prototype.addLocalNotification = function(builderId,
|
||||||
|
content,
|
||||||
|
title,
|
||||||
|
notificaitonID,
|
||||||
|
broadcastTime,
|
||||||
|
extras)
|
||||||
|
JPushPlugin.prototype.removeLocalNotification = function(notificationID)
|
||||||
|
JPushPlugin.prototype.clearLocalNotifications = function()
|
||||||
|
|
||||||
|
#####平台
|
||||||
|
android
|
||||||
|
|
||||||
|
##### 参数说明
|
||||||
|
|
||||||
|
- builderId 设置本地通知样式
|
||||||
|
- content 设置本地通知的content
|
||||||
|
- title 设置本地通知的title
|
||||||
|
- notificaitonID 设置本地通知的ID
|
||||||
|
- broadcastTime 设置本地通知触发时间,为距离当前时间的数值,单位是毫秒
|
||||||
|
- extras 设置额外的数据信息extras为json字符串
|
||||||
|
|
||||||
|
##### 返回值说明
|
||||||
|
|
||||||
|
无
|
||||||
|
|
||||||
|
|
||||||
|
#### API - receiveMessageInAndroidCallback
|
||||||
|
|
||||||
|
用于iOS收到应用内消息的回调函数(请注意和通知的区别),该函数不需要主动调用
|
||||||
|
|
||||||
|
##### 接口定义
|
||||||
|
|
||||||
|
JPushPlugin.prototype.receiveMessageInAndroidCallback = function(data)
|
||||||
|
|
||||||
|
|
||||||
|
#####平台
|
||||||
|
android
|
||||||
|
|
||||||
|
##### 参数说明
|
||||||
|
|
||||||
|
- data 接收到的js字符串
|
||||||
|
|
||||||
|
##### 返回值
|
||||||
|
无
|
||||||
|
|
||||||
|
#### API - receiveMessageInAndroidCallback
|
||||||
|
|
||||||
|
用于iOS收到应用内消息的回调函数(请注意和通知的区别),该函数不需要主动调用
|
||||||
|
|
||||||
|
##### 接口定义
|
||||||
|
|
||||||
|
JPushPlugin.prototype.receiveMessageInAndroidCallback = function(data)
|
||||||
|
|
||||||
|
#####平台
|
||||||
|
android
|
||||||
|
|
||||||
|
##### 参数说明
|
||||||
|
- data 接收到的js字符串,包含的key:value请进入该函数体查看
|
||||||
|
|
||||||
|
##### 返回值
|
||||||
|
无
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
<script type="text/javascript" src="cordova.js"></script>
|
<script type="text/javascript" src="cordova.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var onDeviceReady = function(){
|
var onDeviceReady = function(){
|
||||||
console.log("Device ready!")
|
console.log("JPushPlugin:Device ready!")
|
||||||
initiateUI();
|
initiateUI();
|
||||||
}
|
}
|
||||||
var onTagsWithAlias = function(event){
|
var onTagsWithAlias = function(event){
|
||||||
@@ -28,7 +28,7 @@
|
|||||||
}
|
}
|
||||||
var onGetRegistradionID = function(data) {
|
var onGetRegistradionID = function(data) {
|
||||||
try{
|
try{
|
||||||
console.log("index.registrationID:"+data)
|
console.log("JPushPlugin:registrationID is "+data)
|
||||||
|
|
||||||
$("#registrationid").html(data);
|
$("#registrationid").html(data);
|
||||||
}
|
}
|
||||||
@@ -38,9 +38,18 @@
|
|||||||
}
|
}
|
||||||
var initiateUI = function(){
|
var initiateUI = function(){
|
||||||
|
|
||||||
window.plugins.jPushPlugin.getRegistrationID(onGetRegistradionID);
|
try{
|
||||||
|
window.plugins.jPushPlugin.getRegistrationID(onGetRegistradionID);
|
||||||
|
// var extras={"name":"json"};
|
||||||
|
// window.plugins.jPushPlugin.addLocalNotification(1,"hh","ln",1111,1000*60,extras);
|
||||||
|
// window.plugins.jPushPlugin.removeLocalNotification(1111);
|
||||||
|
// window.plugins.jPushPlugin.clearLocalNotifications();
|
||||||
|
}
|
||||||
|
catch(exception){
|
||||||
|
console.log(exception);
|
||||||
|
}
|
||||||
|
|
||||||
//test android interface
|
//test android interface
|
||||||
//window.plugins.jPushPlugin.getNotification(onNotification);
|
|
||||||
//window.plugins.jPushPlugin.stopPush()
|
//window.plugins.jPushPlugin.stopPush()
|
||||||
//window.plugins.jPushPlugin.resumePush();
|
//window.plugins.jPushPlugin.resumePush();
|
||||||
//window.plugins.jPushPlugin.clearAllNoticication();
|
//window.plugins.jPushPlugin.clearAllNoticication();
|
||||||
@@ -48,7 +57,7 @@
|
|||||||
//window.plugins.jPushPlugin.stopPush();
|
//window.plugins.jPushPlugin.stopPush();
|
||||||
//window.plugins.jPushPlugin.isPushStopped(onIsPushStopped);
|
//window.plugins.jPushPlugin.isPushStopped(onIsPushStopped);
|
||||||
//window.plugins.jPushPlugin.init();
|
//window.plugins.jPushPlugin.init();
|
||||||
//window.plugins.jPushPlugin.setDebugable(true);
|
//window.plugins.jPushPlugin.setDebugMode(true);
|
||||||
//window.plugins.jPushPlugin.startLogPageView("mianPage");
|
//window.plugins.jPushPlugin.startLogPageView("mianPage");
|
||||||
|
|
||||||
$("#setTagWithAliasButton").click(function(ev) {
|
$("#setTagWithAliasButton").click(function(ev) {
|
||||||
@@ -87,11 +96,6 @@
|
|||||||
<body>
|
<body>
|
||||||
<div data-role="page" id="page">
|
<div data-role="page" id="page">
|
||||||
|
|
||||||
<div data-role="header" class="ui-bar ui-bar-b">
|
|
||||||
<center>
|
|
||||||
<img border="0" src="img/logo.png" alt="Urban Airship" align="center" />
|
|
||||||
</center>
|
|
||||||
</div>
|
|
||||||
<div data-role="content">
|
<div data-role="content">
|
||||||
<form>
|
<form>
|
||||||
<div class="ui-body ui-body-b">
|
<div class="ui-body ui-body-b">
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
id="cn.jpush.phonegap.JPushPlugin"
|
id="cn.jpush.phonegap.JPushPlugin"
|
||||||
version="1.5.3">
|
version="2.0.0">
|
||||||
|
|
||||||
<name>JPush Plugin</name>
|
<name>JPush Plugin</name>
|
||||||
<description>JPush for cordova plugin</description>
|
<description>JPush for cordova plugin</description>
|
||||||
@@ -153,10 +153,11 @@
|
|||||||
<receiver android:name="cn.jpush.android.service.AlarmReceiver"/>
|
<receiver android:name="cn.jpush.android.service.AlarmReceiver"/>
|
||||||
<!-- Required . Enable it you can get statistics data with channel -->
|
<!-- Required . Enable it you can get statistics data with channel -->
|
||||||
<meta-data android:name="JPUSH_CHANNEL" android:value="developer-default"/>
|
<meta-data android:name="JPUSH_CHANNEL" android:value="developer-default"/>
|
||||||
<meta-data android:name="JPUSH_APPKEY" android:value="299d0fee887820e7d90a68b2"/>
|
<meta-data android:name="JPUSH_APPKEY" android:value="your appkey"/>
|
||||||
</config-file>
|
</config-file>
|
||||||
<source-file src="src/android/jpush-sdk-release1.6.1.jar" target-dir="libs"/>
|
<source-file src="src/android/jpush-sdk-release1.7.2.jar" target-dir="libs"/>
|
||||||
<source-file src="src/android/libjpush.so" target-dir="libs/armeabi"/>
|
<source-file src="src/android/armeabi/libjpush172.so" target-dir="libs/armeabi"/>
|
||||||
|
<source-file src="src/android/armeabi-v7a/libjpush172.so" target-dir="libs/armeabi-v7a"/>
|
||||||
<source-file src="src/android/JPushPlugin.java" target-dir="src/cn/jpush/phonegap"/>
|
<source-file src="src/android/JPushPlugin.java" target-dir="src/cn/jpush/phonegap"/>
|
||||||
<source-file src="src/android/MyReceiver.java" target-dir="src/cn/jpush/phonegap"/>
|
<source-file src="src/android/MyReceiver.java" target-dir="src/cn/jpush/phonegap"/>
|
||||||
<source-file src="src/android/test_notification_layout.xml" target-dir="res/layout"/>
|
<source-file src="src/android/test_notification_layout.xml" target-dir="res/layout"/>
|
||||||
|
|||||||
@@ -17,12 +17,14 @@ import org.apache.cordova.CordovaWebView;
|
|||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import com.thi.pushtest.R;
|
import your.package.name.R;
|
||||||
|
|
||||||
import cn.jpush.android.api.BasicPushNotificationBuilder;
|
import cn.jpush.android.api.BasicPushNotificationBuilder;
|
||||||
import cn.jpush.android.api.CustomPushNotificationBuilder;
|
import cn.jpush.android.api.CustomPushNotificationBuilder;
|
||||||
import cn.jpush.android.api.JPushInterface;
|
import cn.jpush.android.api.JPushInterface;
|
||||||
|
import cn.jpush.android.data.JPushLocalNotification;
|
||||||
import cn.jpush.android.api.TagAliasCallback;
|
import cn.jpush.android.api.TagAliasCallback;
|
||||||
|
|
||||||
public class JPushPlugin extends CordovaPlugin {
|
public class JPushPlugin extends CordovaPlugin {
|
||||||
@@ -37,19 +39,22 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
"setCustomPushNotificationBuilder",
|
"setCustomPushNotificationBuilder",
|
||||||
"setPushTime",
|
"setPushTime",
|
||||||
"init",
|
"init",
|
||||||
"setDebugable",
|
"setDebugMode",
|
||||||
"stopPush",
|
"stopPush",
|
||||||
"resumePush",
|
"resumePush",
|
||||||
"isPushStopped",
|
"isPushStopped",
|
||||||
"setLatestNotificationNum",
|
"setLatestNotificationNum",
|
||||||
"setPushTime",
|
"setPushTime",
|
||||||
"clearAllNotification");
|
"clearAllNotification",
|
||||||
|
"addLocalNotification",
|
||||||
|
"removeLocalNotification",
|
||||||
|
"clearLocalNotifications");
|
||||||
|
|
||||||
private ExecutorService threadPool = Executors.newFixedThreadPool(1);
|
private ExecutorService threadPool = Executors.newFixedThreadPool(1);
|
||||||
private static JPushPlugin instance;
|
private static JPushPlugin instance;
|
||||||
|
|
||||||
public static String notificationAlert;
|
public static String notificationAlert;
|
||||||
public static Map<String, String> notificationExtras=new HashMap<String, String>();
|
public static Map<String, Object> notificationExtras=new HashMap<String, Object>();
|
||||||
|
|
||||||
public JPushPlugin() {
|
public JPushPlugin() {
|
||||||
instance = this;
|
instance = this;
|
||||||
@@ -58,29 +63,55 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
@Override
|
@Override
|
||||||
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
|
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
|
||||||
super.initialize(cordova, webView);
|
super.initialize(cordova, webView);
|
||||||
JPushInterface.setDebugMode(true);
|
//JPushInterface.setDebugMode(true);
|
||||||
JPushInterface.init(cordova.getActivity().getApplicationContext());
|
//JPushInterface.init(cordova.getActivity().getApplicationContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static JSONObject notificationObject(String message,
|
private static JSONObject notificationObject(String message,
|
||||||
Map<String, String> extras) {
|
Map<String, Object> extras) {
|
||||||
JSONObject data = new JSONObject();
|
JSONObject data = new JSONObject();
|
||||||
try {
|
try {
|
||||||
data.put("message", message);
|
data.put("message", message);
|
||||||
data.put("extras", new JSONObject(extras));
|
JSONObject jExtras = new JSONObject();
|
||||||
|
for(Entry<String,Object> entry:extras.entrySet()){
|
||||||
|
jExtras.put(entry.getKey(),entry.getValue());
|
||||||
|
}
|
||||||
|
if(jExtras.length()>0)
|
||||||
|
{
|
||||||
|
data.put("extras", jExtras);
|
||||||
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void transmitPush(String message, Map<String, String> extras) {
|
private static JSONObject openNotificationObject(String alert,
|
||||||
|
Map<String, Object> extras){
|
||||||
|
JSONObject data = new JSONObject();
|
||||||
|
try{
|
||||||
|
data.put("alert", alert);
|
||||||
|
JSONObject jExtras = new JSONObject();
|
||||||
|
for(Entry<String,Object> entry:extras.entrySet()){
|
||||||
|
jExtras.put(entry.getKey(),entry.getValue());
|
||||||
|
}
|
||||||
|
if(jExtras.length()>0)
|
||||||
|
{
|
||||||
|
data.put("extras", jExtras);
|
||||||
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
static void transmitPush(String message, Map<String, Object> extras) {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
JSONObject data = notificationObject(message, extras);
|
JSONObject data = notificationObject(message, extras);
|
||||||
String js = String
|
String js = String
|
||||||
.format("window.plugins.jPushPlugin.pushCallback(%s);",
|
.format("window.plugins.jPushPlugin.receiveMessageInAndroidCallback('%s');",
|
||||||
data.toString());
|
data.toString());
|
||||||
try {
|
try {
|
||||||
instance.webView.sendJavascript(js);
|
instance.webView.sendJavascript(js);
|
||||||
@@ -90,7 +121,22 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
static void transmitOpen(String alert, Map<String, Object> extras) {
|
||||||
|
if (instance == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
JSONObject data = openNotificationObject(alert, extras);
|
||||||
|
String js = String
|
||||||
|
.format("window.plugins.jPushPlugin.openNotificationInAndroidCallback('%s');",
|
||||||
|
data.toString());
|
||||||
|
try {
|
||||||
|
instance.webView.sendJavascript(js);
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final String action, final JSONArray data,
|
public boolean execute(final String action, final JSONArray data,
|
||||||
final CallbackContext callbackContext) throws JSONException {
|
final CallbackContext callbackContext) throws JSONException {
|
||||||
@@ -114,20 +160,21 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
|
|
||||||
void init(JSONArray data,CallbackContext callbackContext){
|
void init(JSONArray data,CallbackContext callbackContext){
|
||||||
JPushInterface.init(this.cordova.getActivity().getApplicationContext());
|
JPushInterface.init(this.cordova.getActivity().getApplicationContext());
|
||||||
callbackContext.success();
|
//callbackContext.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setDebugable(JSONArray data, CallbackContext callbackContext) {
|
void setDebugMode(JSONArray data, CallbackContext callbackContext) {
|
||||||
String mode;
|
boolean mode;
|
||||||
try {
|
try {
|
||||||
mode = data.getString(0);
|
mode = data.getBoolean(0);
|
||||||
if (mode.equals("true")) {
|
// if (mode.equals("true")) {
|
||||||
JPushInterface.setDebugMode(true);
|
// JPushInterface.setDebugMode(true);
|
||||||
} else if (mode.equals("false")) {
|
// } else if (mode.equals("false")) {
|
||||||
JPushInterface.setDebugMode(false);
|
// JPushInterface.setDebugMode(false);
|
||||||
} else {
|
// } else {
|
||||||
callbackContext.error("error mode");
|
// callbackContext.error("error mode");
|
||||||
}
|
// }
|
||||||
|
JPushInterface.setDebugMode(mode);
|
||||||
callbackContext.success();
|
callbackContext.success();
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
}
|
}
|
||||||
@@ -147,8 +194,8 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
|
|
||||||
void isPushStopped(JSONArray data,
|
void isPushStopped(JSONArray data,
|
||||||
CallbackContext callbackContext){
|
CallbackContext callbackContext){
|
||||||
boolean isStoped =JPushInterface.isPushStopped(this.cordova.getActivity().getApplicationContext());
|
boolean isStopped =JPushInterface.isPushStopped(this.cordova.getActivity().getApplicationContext());
|
||||||
if(isStoped){
|
if(isStopped){
|
||||||
callbackContext.success(1);
|
callbackContext.success(1);
|
||||||
}else{
|
}else{
|
||||||
callbackContext.success(0);
|
callbackContext.success(0);
|
||||||
@@ -165,7 +212,7 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
callbackContext.error("error reading num json");
|
callbackContext.error("error reading num json");
|
||||||
}
|
}
|
||||||
if(num != -1){
|
if(num != -1){
|
||||||
JPushInterface.setLatestNotifactionNumber(this.cordova.getActivity().getApplicationContext(), num);
|
JPushInterface.setLatestNotificationNumber(this.cordova.getActivity().getApplicationContext(), num);
|
||||||
}else{
|
}else{
|
||||||
callbackContext.error("error num");
|
callbackContext.error("error num");
|
||||||
}
|
}
|
||||||
@@ -174,13 +221,13 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
void setPushTime(JSONArray data,
|
void setPushTime(JSONArray data,
|
||||||
CallbackContext callbackContext){
|
CallbackContext callbackContext){
|
||||||
Set<Integer> days = new HashSet<Integer>();
|
Set<Integer> days = new HashSet<Integer>();
|
||||||
JSONArray dayArr;
|
JSONArray dayArray;
|
||||||
int startHour = -1;
|
int startHour = -1;
|
||||||
int endHour = -1;
|
int endHour = -1;
|
||||||
try {
|
try {
|
||||||
dayArr = data.getJSONArray(0);
|
dayArray = data.getJSONArray(0);
|
||||||
for (int i = 0; i < dayArr.length(); i++) {
|
for (int i = 0; i < dayArray.length(); i++) {
|
||||||
days.add(dayArr.getInt(i));
|
days.add(dayArray.getInt(i));
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -212,8 +259,11 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
tags= new HashSet<String>();
|
tags= new HashSet<String>();
|
||||||
}else{
|
}else{
|
||||||
tagStr = data.getString(0);
|
tagStr = data.getString(0);
|
||||||
String[] tagArr = tagStr.split(",");
|
String[] tagArray = tagStr.split(",");
|
||||||
for (String tag : tagArr) {
|
for (String tag : tagArray) {
|
||||||
|
if(tags==null){
|
||||||
|
tags= new HashSet<String>();
|
||||||
|
}
|
||||||
tags.add(tag);
|
tags.add(tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -244,9 +294,9 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
String alias;
|
String alias;
|
||||||
try {
|
try {
|
||||||
alias = data.getString(0);
|
alias = data.getString(0);
|
||||||
JSONArray tagsArr = data.getJSONArray(1);
|
JSONArray tagsArray = data.getJSONArray(1);
|
||||||
for (int i = 0; i < tagsArr.length(); i++) {
|
for (int i = 0; i < tagsArray.length(); i++) {
|
||||||
tags.add(tagsArr.getString(i));
|
tags.add(tagsArray.getString(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
JPushInterface.setAliasAndTags(this.cordova.getActivity()
|
JPushInterface.setAliasAndTags(this.cordova.getActivity()
|
||||||
@@ -258,23 +308,23 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void getNotification(JSONArray data, CallbackContext callBackContext) {
|
// void getNotification(JSONArray data, CallbackContext callBackContext) {
|
||||||
String alert = JPushPlugin.notificationAlert;
|
// String alert = JPushPlugin.notificationAlert;
|
||||||
Map<String, String> extras = JPushPlugin.notificationExtras;
|
// Map<String, String> extras = JPushPlugin.notificationExtras;
|
||||||
|
//
|
||||||
JSONObject jsonData = new JSONObject();
|
// JSONObject jsonData = new JSONObject();
|
||||||
try {
|
// try {
|
||||||
jsonData.put("message", alert);
|
// jsonData.put("message", alert);
|
||||||
jsonData.put("extras", new JSONObject(extras));
|
// jsonData.put("extras", new JSONObject(extras));
|
||||||
} catch (JSONException e) {
|
// } catch (JSONException e) {
|
||||||
e.printStackTrace();
|
// e.printStackTrace();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
callBackContext.success(jsonData);
|
// callBackContext.success(jsonData);
|
||||||
|
//
|
||||||
JPushPlugin.notificationAlert = "";
|
// JPushPlugin.notificationAlert = "";
|
||||||
JPushPlugin.notificationExtras = new HashMap<String, String>();
|
// JPushPlugin.notificationExtras = new HashMap<String, Obl>();
|
||||||
}
|
// }
|
||||||
|
|
||||||
void setBasicPushNotificationBuilder(JSONArray data,
|
void setBasicPushNotificationBuilder(JSONArray data,
|
||||||
CallbackContext callbackContext) {
|
CallbackContext callbackContext) {
|
||||||
@@ -288,7 +338,7 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
callbackContext.success(obj);
|
//callbackContext.success(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setCustomPushNotificationBuilder(JSONArray data,
|
void setCustomPushNotificationBuilder(JSONArray data,
|
||||||
@@ -305,13 +355,13 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
callbackContext.success(obj);
|
//callbackContext.success(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearAllNotification(JSONArray data,
|
void clearAllNotification(JSONArray data,
|
||||||
CallbackContext callbackContext){
|
CallbackContext callbackContext){
|
||||||
JPushInterface.clearAllNotifications(this.cordova.getActivity());
|
JPushInterface.clearAllNotifications(this.cordova.getActivity());
|
||||||
callbackContext.success();
|
//callbackContext.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearNotificationById(JSONArray data,
|
void clearNotificationById(JSONArray data,
|
||||||
@@ -329,6 +379,41 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
callbackContext.error("error id");
|
callbackContext.error("error id");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void addLocalNotification(JSONArray data,
|
||||||
|
CallbackContext callbackContext) throws JSONException{
|
||||||
|
//builderId,content,title,notificaitonID,broadcastTime,extras
|
||||||
|
|
||||||
|
int builderId=data.getInt(0);
|
||||||
|
String content =data.getString(1);
|
||||||
|
String title = data.getString(2);
|
||||||
|
int notificationID= data.getInt(3);
|
||||||
|
int broadcastTime=data.getInt(4);
|
||||||
|
JSONObject extras=data.getJSONObject(5);
|
||||||
|
|
||||||
|
JPushLocalNotification ln = new JPushLocalNotification();
|
||||||
|
ln.setBuilderId(builderId);
|
||||||
|
ln.setContent(content);
|
||||||
|
ln.setTitle(title);
|
||||||
|
ln.setNotificationId(notificationID) ;
|
||||||
|
ln.setBroadcastTime(System.currentTimeMillis() + broadcastTime);
|
||||||
|
|
||||||
|
ln.setExtras(extras.toString()) ;
|
||||||
|
JPushInterface.addLocalNotification(this.cordova.getActivity(), ln);
|
||||||
|
|
||||||
|
}
|
||||||
|
void removeLocalNotification(JSONArray data,
|
||||||
|
CallbackContext callbackContext) throws JSONException{
|
||||||
|
|
||||||
|
int notificationID=data.getInt(0);
|
||||||
|
JPushInterface.removeLocalNotification(this.cordova.getActivity(),notificationID);
|
||||||
|
|
||||||
|
}
|
||||||
|
void clearLocalNotifications(JSONArray data,
|
||||||
|
CallbackContext callbackContext){
|
||||||
|
|
||||||
|
JPushInterface.clearLocalNotifications(this.cordova.getActivity());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private final TagAliasCallback mTagWithAliasCallback = new TagAliasCallback() {
|
private final TagAliasCallback mTagWithAliasCallback = new TagAliasCallback() {
|
||||||
|
|
||||||
@@ -348,10 +433,6 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
.format("cordova.fireDocumentEvent('jpush.setTagsWithAlias',%s)",
|
.format("cordova.fireDocumentEvent('jpush.setTagsWithAlias',%s)",
|
||||||
data.toString());
|
data.toString());
|
||||||
instance.webView.sendJavascript(jsEvent);
|
instance.webView.sendJavascript(jsEvent);
|
||||||
String js = String
|
|
||||||
.format("window.plugins.jPushPlugin.pushCallback('%s');",
|
|
||||||
data.toString());
|
|
||||||
instance.webView.sendJavascript(js);
|
|
||||||
|
|
||||||
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
|
|||||||
@@ -35,13 +35,13 @@ public class MyReceiver extends BroadcastReceiver {
|
|||||||
}
|
}
|
||||||
private void handlingReceivedMessage(Intent intent) {
|
private void handlingReceivedMessage(Intent intent) {
|
||||||
String msg = intent.getStringExtra(JPushInterface.EXTRA_MESSAGE);
|
String msg = intent.getStringExtra(JPushInterface.EXTRA_MESSAGE);
|
||||||
Map<String,String> extras = getNotificationExtras(intent);
|
Map<String,Object> extras = getNotificationExtras(intent);
|
||||||
|
|
||||||
JPushPlugin.transmitPush(msg, extras);
|
JPushPlugin.transmitPush(msg, extras);
|
||||||
}
|
}
|
||||||
private void handlingNotificationOpen(Context context,Intent intent){
|
private void handlingNotificationOpen(Context context,Intent intent){
|
||||||
String alert = intent.getStringExtra(JPushInterface.EXTRA_ALERT);
|
String alert = intent.getStringExtra(JPushInterface.EXTRA_ALERT);
|
||||||
Map<String,String> extras = getNotificationExtras(intent);
|
Map<String,Object> extras = getNotificationExtras(intent);
|
||||||
|
|
||||||
Intent launch = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
|
Intent launch = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
|
||||||
launch.addCategory(Intent.CATEGORY_LAUNCHER);
|
launch.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||||
@@ -50,19 +50,25 @@ public class MyReceiver extends BroadcastReceiver {
|
|||||||
JPushPlugin.notificationAlert = alert;
|
JPushPlugin.notificationAlert = alert;
|
||||||
JPushPlugin.notificationExtras = extras;
|
JPushPlugin.notificationExtras = extras;
|
||||||
|
|
||||||
|
JPushPlugin.transmitOpen(alert, extras);
|
||||||
|
|
||||||
context.startActivity(launch);
|
context.startActivity(launch);
|
||||||
}
|
}
|
||||||
private Map<String, String> getNotificationExtras(Intent intent) {
|
private Map<String, Object> getNotificationExtras(Intent intent) {
|
||||||
Map<String, String> extrasMap = new HashMap<String, String>();
|
Map<String, Object> extrasMap = new HashMap<String, Object>();
|
||||||
|
|
||||||
for (String key : intent.getExtras().keySet()) {
|
for (String key : intent.getExtras().keySet()) {
|
||||||
if (!IGNORED_EXTRAS_KEYS.contains(key)) {
|
if (!IGNORED_EXTRAS_KEYS.contains(key)) {
|
||||||
Log.e("key","key:"+key);
|
Log.e("key","key:"+key);
|
||||||
extrasMap.put(key, intent.getStringExtra(key));
|
if (key.equals(JPushInterface.EXTRA_NOTIFICATION_ID)){
|
||||||
|
extrasMap.put(key, intent.getIntExtra(key,0));
|
||||||
|
}else{
|
||||||
|
extrasMap.put(key, intent.getStringExtra(key));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return extrasMap;
|
return extrasMap;
|
||||||
}
|
}
|
||||||
private static final List<String> IGNORED_EXTRAS_KEYS =
|
private static final List<String> IGNORED_EXTRAS_KEYS =
|
||||||
Arrays.asList("cn.jpush.android.TITLE","cn.jpush.android.MESSAGE","cn.jpush.android.APPKEY");
|
Arrays.asList("cn.jpush.android.TITLE","cn.jpush.android.MESSAGE","cn.jpush.android.APPKEY","cn.jpush.android.NOTIFICATION_CONTENT_TITLE");
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
src/android/armeabi-v7a/libjpush172.so
Normal file
BIN
src/android/armeabi-v7a/libjpush172.so
Normal file
Binary file not shown.
BIN
src/android/armeabi/libjpush172.so
Normal file
BIN
src/android/armeabi/libjpush172.so
Normal file
Binary file not shown.
Binary file not shown.
BIN
src/android/jpush-sdk-release1.7.2.jar
Normal file
BIN
src/android/jpush-sdk-release1.7.2.jar
Normal file
Binary file not shown.
Binary file not shown.
@@ -11,11 +11,24 @@
|
|||||||
|
|
||||||
@implementation JPushPlugin
|
@implementation JPushPlugin
|
||||||
|
|
||||||
|
- (CDVPlugin*)initWithWebView:(UIWebView*)theWebView{
|
||||||
|
if (self=[super initWithWebView:theWebView]) {
|
||||||
|
|
||||||
|
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
|
||||||
|
[defaultCenter addObserver:self
|
||||||
|
selector:@selector(networkDidReceiveMessage:)
|
||||||
|
name:kJPFNetworkDidReceiveMessageNotification
|
||||||
|
object:nil];
|
||||||
|
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command{
|
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command{
|
||||||
|
|
||||||
NSArray *arguments=command.arguments;
|
NSArray *arguments=command.arguments;
|
||||||
if (!arguments||[arguments count]<2) {
|
if (!arguments||[arguments count]<2) {
|
||||||
[self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.pushCallback('%@')",@""]];
|
// [self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.pushCallback('%@')",@""]];
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
NSString *alias=[arguments objectAtIndex:0];
|
NSString *alias=[arguments objectAtIndex:0];
|
||||||
@@ -51,8 +64,8 @@
|
|||||||
|
|
||||||
-(void)getRegistrationID:(CDVInvokedUrlCommand*)command{
|
-(void)getRegistrationID:(CDVInvokedUrlCommand*)command{
|
||||||
|
|
||||||
NSString* registratonID = [APService registrionID];
|
NSString* registrationID = [APService registrationID];
|
||||||
CDVPluginResult *result=[self pluginResultForValue:registratonID];
|
CDVPluginResult *result=[self pluginResultForValue:registrationID];
|
||||||
if (result) {
|
if (result) {
|
||||||
[self succeedWithPluginResult:result withCallbackID:command.callbackId];
|
[self succeedWithPluginResult:result withCallbackID:command.callbackId];
|
||||||
} else {
|
} else {
|
||||||
@@ -78,7 +91,7 @@
|
|||||||
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.setTagsWithAlias',%@)",jsonString]];
|
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.setTagsWithAlias',%@)",jsonString]];
|
||||||
[self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.pushCallback('%@')",jsonString]];
|
// [self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.pushCallback('%@')",jsonString]];
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -106,7 +119,44 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
-(void)beginLogPageView:(CDVInvokedUrlCommand*)command{
|
||||||
|
NSArray *arguments=command.arguments;
|
||||||
|
if (!arguments||[arguments count]<2) {
|
||||||
|
NSLog(@"beginLogPageView argument error");
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
NSString * pageName=[arguments objectAtIndex:0];
|
||||||
|
int duration=[[arguments objectAtIndex:0]intValue];
|
||||||
|
if (pageName) {
|
||||||
|
[APService beginLogPageView:pageName duration:duration];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
-(void)setBadge:(CDVInvokedUrlCommand*)command{
|
||||||
|
NSArray *argument=command.arguments;
|
||||||
|
if ([argument count]<1) {
|
||||||
|
NSLog(@"setBadge argument error!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
NSNumber *badge=[argument objectAtIndex:0];
|
||||||
|
[APService setBadge:[badge intValue]];
|
||||||
|
}
|
||||||
|
-(void)resetBadge:(CDVInvokedUrlCommand*)command{
|
||||||
|
[APService resetBadge];
|
||||||
|
}
|
||||||
|
-(void)setDebugModeFromIos:(CDVInvokedUrlCommand*)command{
|
||||||
|
|
||||||
|
[APService setDebugMode];
|
||||||
|
}
|
||||||
|
-(void)setLogOFF:(CDVInvokedUrlCommand*)command{
|
||||||
|
|
||||||
|
[APService setLogOFF];
|
||||||
|
}
|
||||||
|
-(void)stopPush:(CDVInvokedUrlCommand*)command{
|
||||||
|
|
||||||
|
[[UIApplication sharedApplication]unregisterForRemoteNotifications];
|
||||||
|
|
||||||
|
}
|
||||||
- (void)failWithCallbackID:(NSString *)callbackID {
|
- (void)failWithCallbackID:(NSString *)callbackID {
|
||||||
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
|
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
|
||||||
[self.commandDelegate sendPluginResult:result callbackId:callbackID];
|
[self.commandDelegate sendPluginResult:result callbackId:callbackID];
|
||||||
@@ -141,5 +191,23 @@
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)networkDidReceiveMessage:(NSNotification *)notification {
|
||||||
|
|
||||||
|
NSDictionary *userInfo = [notification userInfo];
|
||||||
|
NSLog(@"%@",userInfo);
|
||||||
|
|
||||||
|
NSError *error;
|
||||||
|
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:0 error:&error];
|
||||||
|
NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
|
||||||
|
|
||||||
|
NSLog(@"%@",jsonString);
|
||||||
|
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
|
||||||
|
[self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.receiveMessageIniOSCallback('%@')",jsonString]];
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -4,23 +4,27 @@
|
|||||||
//
|
//
|
||||||
// Created by JPush on 12-8-15.
|
// Created by JPush on 12-8-15.
|
||||||
// Copyright (c) 2012年 HXHG. All rights reserved.
|
// Copyright (c) 2012年 HXHG. All rights reserved.
|
||||||
// Version: 1.7.1
|
// Version: 1.8.1
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
@class CLRegion;
|
||||||
|
@class UILocalNotification;
|
||||||
|
|
||||||
extern NSString *const kAPNetworkDidSetupNotification; // 建立连接
|
extern NSString *const kJPFNetworkDidSetupNotification; // 建立连接
|
||||||
extern NSString *const kAPNetworkDidCloseNotification; // 关闭连接
|
extern NSString *const kJPFNetworkDidCloseNotification; // 关闭连接
|
||||||
extern NSString *const kAPNetworkDidRegisterNotification; // 注册成功
|
extern NSString *const kJPFNetworkDidRegisterNotification; // 注册成功
|
||||||
extern NSString *const kAPNetworkDidLoginNotification; // 登录成功
|
extern NSString *const kJPFNetworkDidLoginNotification; // 登录成功
|
||||||
extern NSString *const
|
extern NSString *const
|
||||||
kAPNetworkDidReceiveMessageNotification; // 收到消息(非APNS)
|
kJPFNetworkDidReceiveMessageNotification; // 收到消息(非APNS)
|
||||||
extern NSString *const kAPServiceErrorNotification; // 错误提示
|
extern NSString *const kJPFServiceErrorNotification; // 错误提示
|
||||||
|
|
||||||
|
@class CLLocation;
|
||||||
@interface APService : NSObject
|
@interface APService : NSObject
|
||||||
|
|
||||||
|
#pragma - mark 基本功能
|
||||||
// 以下四个接口是必须调用的
|
// 以下四个接口是必须调用的
|
||||||
+ (void)setupWithOption:(NSDictionary *)launchingOption; // 初始化
|
+ (void)setupWithOption:(NSDictionary *)launchingOption; // 初始化
|
||||||
+ (void)registerForRemoteNotificationTypes:(int)types; // 注册APNS类型
|
+ (void)registerForRemoteNotificationTypes:(NSUInteger)types
|
||||||
|
categories:(NSSet *)categories; // 注册APNS类型
|
||||||
+ (void)registerDeviceToken:(NSData *)deviceToken; // 向服务器上报Device Token
|
+ (void)registerDeviceToken:(NSData *)deviceToken; // 向服务器上报Device Token
|
||||||
+ (void)handleRemoteNotification:(NSDictionary *)
|
+ (void)handleRemoteNotification:(NSDictionary *)
|
||||||
remoteInfo; // 处理收到的APNS消息,向服务器上报收到APNS消息
|
remoteInfo; // 处理收到的APNS消息,向服务器上报收到APNS消息
|
||||||
@@ -44,6 +48,7 @@ extern NSString *const kAPServiceErrorNotification; // 错误提示
|
|||||||
// 用于过滤出正确可用的tags,如果总数量超出最大限制则返回最大数量的靠前的可用tags
|
// 用于过滤出正确可用的tags,如果总数量超出最大限制则返回最大数量的靠前的可用tags
|
||||||
+ (NSSet *)filterValidTags:(NSSet *)tags;
|
+ (NSSet *)filterValidTags:(NSSet *)tags;
|
||||||
|
|
||||||
|
#pragma - mark 上报日志
|
||||||
/**
|
/**
|
||||||
* 记录页面停留时间功能。
|
* 记录页面停留时间功能。
|
||||||
* startLogPageView和stopLogPageView为自动计算停留时间
|
* startLogPageView和stopLogPageView为自动计算停留时间
|
||||||
@@ -56,13 +61,121 @@ extern NSString *const kAPServiceErrorNotification; // 错误提示
|
|||||||
+ (void)stopLogPageView:(NSString *)pageName;
|
+ (void)stopLogPageView:(NSString *)pageName;
|
||||||
+ (void)beginLogPageView:(NSString *)pageName duration:(int)seconds;
|
+ (void)beginLogPageView:(NSString *)pageName duration:(int)seconds;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开启Crash日志收集, 默认是关闭状态.
|
||||||
|
*/
|
||||||
|
+ (void)crashLogON;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 地理位置设置
|
||||||
|
* 为了更精确的统计用户地理位置,可以调用此方法传入经纬度信息
|
||||||
|
* 需要链接 CoreLocation.framework 并且 #import <CoreLocation/CoreLocation.h>
|
||||||
|
* @param latitude 纬度.
|
||||||
|
* @param longitude 经度.
|
||||||
|
* @param location 直接传递CLLocation *型的地理信息
|
||||||
|
*/
|
||||||
|
+ (void)setLatitude:(double)latitude longitude:(double)longitude;
|
||||||
|
+ (void)setLocation:(CLLocation *)location;
|
||||||
|
|
||||||
|
#pragma - mark 本地通知
|
||||||
|
/**
|
||||||
|
* 本地推送,最多支持64个
|
||||||
|
* @param fireDate 本地推送触发的时间
|
||||||
|
* @param alertBody 本地推送需要显示的内容
|
||||||
|
* @param badge 角标的数字。如果不需要改变角标传-1
|
||||||
|
* @param alertAction 弹框的按钮显示的内容(IOS 8默认为"打开",其他默认为"启动")
|
||||||
|
* @param notificationKey 本地推送标示符
|
||||||
|
* @param userInfo 自定义参数,可以用来标识推送和增加附加信息
|
||||||
|
* @param soundName 自定义通知声音,设置为nil为默认声音
|
||||||
|
|
||||||
|
* IOS8新参数
|
||||||
|
* @param region 自定义参数
|
||||||
|
* @param regionTriggersOnce 自定义参数
|
||||||
|
* @param category 自定义参数
|
||||||
|
*/
|
||||||
|
+ (UILocalNotification *)setLocalNotification:(NSDate *)fireDate
|
||||||
|
alertBody:(NSString *)alertBody
|
||||||
|
badge:(int)badge
|
||||||
|
alertAction:(NSString *)alertAction
|
||||||
|
identifierKey:(NSString *)notificationKey
|
||||||
|
userInfo:(NSDictionary *)userInfo
|
||||||
|
soundName:(NSString *)soundName;
|
||||||
|
|
||||||
|
+ (UILocalNotification *)setLocalNotification:(NSDate *)fireDate
|
||||||
|
alertBody:(NSString *)alertBody
|
||||||
|
badge:(int)badge
|
||||||
|
alertAction:(NSString *)alertAction
|
||||||
|
identifierKey:(NSString *)notificationKey
|
||||||
|
userInfo:(NSDictionary *)userInfo
|
||||||
|
soundName:(NSString *)soundName
|
||||||
|
region:(CLRegion *)region
|
||||||
|
regionTriggersOnce:(BOOL)regionTriggersOnce
|
||||||
|
category:(NSString *)category
|
||||||
|
NS_AVAILABLE_IOS(8_0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 本地推送在前台推送。默认App在前台运行时不会进行弹窗,在程序接收通知调用此接口可实现指定的推送弹窗。
|
||||||
|
* @param notification 本地推送对象
|
||||||
|
* @param notificationKey 需要前台显示的本地推送通知的标示符
|
||||||
|
*/
|
||||||
|
+ (void)showLocalNotificationAtFront:(UILocalNotification *)notification
|
||||||
|
identifierKey:(NSString *)notificationKey;
|
||||||
|
/**
|
||||||
|
* 删除本地推送
|
||||||
|
* @param notificationKey 本地推送标示符
|
||||||
|
* @param myUILocalNotification 本地推送对象
|
||||||
|
*/
|
||||||
|
+ (void)deleteLocalNotificationWithIdentifierKey:(NSString *)notificationKey;
|
||||||
|
+ (void)deleteLocalNotification:(UILocalNotification *)localNotification;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取指定通知
|
||||||
|
* @param notificationKey 本地推送标示符
|
||||||
|
* @return 本地推送对象数组,[array count]为0时表示没找到
|
||||||
|
*/
|
||||||
|
+ (NSArray *)findLocalNotificationWithIdentifier:(NSString *)notificationKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除所有本地推送对象
|
||||||
|
*/
|
||||||
|
+ (void)clearAllLocalNotifications;
|
||||||
|
|
||||||
|
#pragma - mark 设置Badge
|
||||||
|
/**
|
||||||
|
* set setBadge
|
||||||
|
* @param value 设置JPush服务器的badge的值
|
||||||
|
* 本地仍须调用UIApplication:setApplicationIconBadgeNumber函数,来设置脚标
|
||||||
|
*/
|
||||||
|
+ (BOOL)setBadge:(NSInteger)value;
|
||||||
|
/**
|
||||||
|
* set setBadge
|
||||||
|
* @param value 清除JPush服务器对badge值的设定.
|
||||||
|
* 本地仍须调用UIApplication:setApplicationIconBadgeNumber函数,来设置脚标
|
||||||
|
*/
|
||||||
|
|
||||||
|
+ (void)resetBadge;
|
||||||
|
|
||||||
|
#pragma - mark 获取用户标示符
|
||||||
/**
|
/**
|
||||||
* get the UDID
|
* get the UDID
|
||||||
*/
|
*/
|
||||||
+ (NSString *)openUDID DEPRECATED_ATTRIBUTE; // UDID
|
+ (NSString *)openUDID DEPRECATED_ATTRIBUTE; // UDID
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get RegistionID
|
* get RegistrationID
|
||||||
*/
|
*/
|
||||||
+ (NSString *)registrionID;
|
+ (NSString *)registrationID;
|
||||||
|
|
||||||
|
#pragma - mark 打印日志信息配置
|
||||||
|
/**
|
||||||
|
* setDebugMode获取更多的Log信息
|
||||||
|
* 开发过程中建议开启DebugMode
|
||||||
|
*
|
||||||
|
* setLogOFF关闭除了错误信息外的所有Log
|
||||||
|
* 发布时建议开启LogOFF用于节省性能开销
|
||||||
|
*
|
||||||
|
* 默认为不开启DebugLog,只显示基本的信息
|
||||||
|
*/
|
||||||
|
+ (void)setDebugMode;
|
||||||
|
+ (void)setLogOFF;
|
||||||
@end
|
@end
|
||||||
|
|||||||
Binary file not shown.
@@ -1,5 +1,7 @@
|
|||||||
|
|
||||||
var JPushPlugin = function(){
|
var JPushPlugin = function(){
|
||||||
};
|
};
|
||||||
|
//private plugin function
|
||||||
|
|
||||||
JPushPlugin.prototype.isPlatformIOS = function(){
|
JPushPlugin.prototype.isPlatformIOS = function(){
|
||||||
return device.platform == "iPhone" || device.platform == "iPad" || device.platform == "iPod touch" || device.platform == "iOS"
|
return device.platform == "iPhone" || device.platform == "iPad" || device.platform == "iPod touch" || device.platform == "iOS"
|
||||||
@@ -14,16 +16,23 @@ JPushPlugin.prototype.call_native = function(name, args, callback){
|
|||||||
ret = cordova.exec(callback,this.error_callback,'JPushPlugin',name,args);
|
ret = cordova.exec(callback,this.error_callback,'JPushPlugin',name,args);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
//public plugin function
|
||||||
|
|
||||||
JPushPlugin.prototype.startLogPageView = function(data){
|
JPushPlugin.prototype.startLogPageView = function(pageName){
|
||||||
if(this.isPlatformIOS()){
|
if(this.isPlatformIOS()){
|
||||||
this.call_native( "startLogPageView",[data],null);
|
this.call_native( "startLogPageView",[pageName],null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
JPushPlugin.prototype.stopLogPageView = function(data){
|
JPushPlugin.prototype.stopLogPageView = function(pageName){
|
||||||
if(this.isPlatformIOS()){
|
if(this.isPlatformIOS()){
|
||||||
this.call_native( "stopLogPageView",[data],null);
|
this.call_native( "stopLogPageView",[pageName],null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JPushPlugin.prototype.beginLogPageView = function(pageName,duration){
|
||||||
|
if(this.isPlatformIOS()){
|
||||||
|
this.call_native( "beginLogPageView",[pageName,duration],null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,7 +55,24 @@ JPushPlugin.prototype.setTagsWithAlias = function(tags,alias){
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
JPushPlugin.prototype.setTags = function(tags){
|
||||||
|
|
||||||
|
try{
|
||||||
|
this.call_native("setTags",tags,null);
|
||||||
|
}
|
||||||
|
catch(exception){
|
||||||
|
console.log(exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JPushPlugin.prototype.setAlias = function(alias){
|
||||||
|
try{
|
||||||
|
this.call_native("setAlias",[alias],null);
|
||||||
|
}
|
||||||
|
catch(exception){
|
||||||
|
console.log(exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
JPushPlugin.prototype.getRegistrationID = function(callback){
|
JPushPlugin.prototype.getRegistrationID = function(callback){
|
||||||
|
|
||||||
try{
|
try{
|
||||||
@@ -57,33 +83,89 @@ JPushPlugin.prototype.getRegistrationID = function(callback){
|
|||||||
console.log(exception);
|
console.log(exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
JPushPlugin.prototype.setTags = function(data){
|
|
||||||
|
JPushPlugin.prototype.setBadge = function(value){
|
||||||
try{
|
|
||||||
this.call_native("setTags",data,null);
|
if(this.isPlatformIOS()){
|
||||||
|
try{
|
||||||
|
this.call_native("setBadge",[value],null);
|
||||||
|
}
|
||||||
|
catch(exception){
|
||||||
|
console.log(exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
JPushPlugin.prototype.resetBadge = function(){
|
||||||
|
|
||||||
|
if(this.isPlatformIOS()){
|
||||||
|
try{
|
||||||
|
var data=[];
|
||||||
|
this.call_native("resetBadge",[data],null);
|
||||||
|
}
|
||||||
|
catch(exception){
|
||||||
|
console.log(exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
JPushPlugin.prototype.setDebugModeFromIos = function(){
|
||||||
|
if(this.isPlatformIOS()){
|
||||||
|
var data=[];
|
||||||
|
this.call_native("setDebugModeFromIos",[data],null);
|
||||||
}
|
}
|
||||||
catch(exception){
|
|
||||||
console.log(exception);
|
}
|
||||||
|
JPushPlugin.prototype.setLogOFF = function(){
|
||||||
|
if(this.isPlatformIOS()){
|
||||||
|
var data=[];
|
||||||
|
this.call_native("setLogOFF",[data],null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
JPushPlugin.prototype.receiveMessageIniOSCallback = function(data){
|
||||||
JPushPlugin.prototype.setAlias = function(data){
|
try{
|
||||||
try{
|
console.log("JPushPlugin:receiveMessageIniOSCallback--data:"+data);
|
||||||
this.call_native("setAlias",[data],null);
|
var bToObj = JSON.parse(data);
|
||||||
|
var content = bToObj.content;
|
||||||
|
console.log(content);
|
||||||
}
|
}
|
||||||
catch(exception){
|
catch(exception){
|
||||||
console.log(exception);
|
console.log("JPushPlugin:receiveMessageIniOSCallback"+exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
JPushPlugin.prototype.receiveMessageInAndroidCallback = function(data){
|
||||||
JPushPlugin.prototype.pushCallback = function(data){
|
|
||||||
try{
|
try{
|
||||||
|
console.log("JPushPlugin:receiveMessageInAndroidCallback");
|
||||||
|
//console.log(data);
|
||||||
|
//ecvar bToObj=JSON.parse(data);
|
||||||
|
//var message = bToObj.message;
|
||||||
|
//var extras = bToObj.extras;
|
||||||
|
|
||||||
|
//console.log(message);
|
||||||
|
//console.log(extras['cn.jpush.android.MSG_ID']);
|
||||||
|
//console.log(extras['cn.jpush.android.CONTENT_TYPE']);
|
||||||
|
//console.log(extras['cn.jpush.android.EXTRA']);
|
||||||
|
}
|
||||||
|
catch(exception){
|
||||||
|
console.log("JPushPlugin:pushCallback "+exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//
|
||||||
|
JPushPlugin.prototype.openNotificationInAndroidCallback = function(data){
|
||||||
|
try{
|
||||||
|
console.log("JPushPlugin:openNotificationInAndroidCallback");
|
||||||
console.log(data);
|
console.log(data);
|
||||||
var bToObj=JSON.parse(data);
|
//var bToObj = JSON.parse(data);
|
||||||
var code = bToObj.resultCode;
|
//var alert = bToObj.alert;
|
||||||
var tags = bToObj.resultTags;
|
//var extras = bToObj.extras;
|
||||||
var alias = bToObj.resultAlias;
|
//console.log(alert);
|
||||||
console.log("JPushPlugin:callBack--code is "+code+" tags is "+tags + " alias is "+alias);
|
|
||||||
|
//console.log(extras['cn.jpush.android.MSG_ID']);
|
||||||
|
//console.log(extras['app']);
|
||||||
|
//console.log(extras['cn.jpush.android.NOTIFICATION_CONTENT_TITLE']);
|
||||||
|
//console.log(extras['cn.jpush.android.EXTRA']);
|
||||||
|
//console.log(extras['cn.jpush.android.PUSH_ID']);
|
||||||
|
//console.log(extras['cn.jpush.android.NOTIFICATION_ID']);
|
||||||
|
//console.log("JPushPlugin:openNotificationCallback is ready");
|
||||||
}
|
}
|
||||||
catch(exception){
|
catch(exception){
|
||||||
console.log(exception);
|
console.log(exception);
|
||||||
@@ -91,13 +173,6 @@ JPushPlugin.prototype.pushCallback = function(data){
|
|||||||
}
|
}
|
||||||
//android single
|
//android single
|
||||||
|
|
||||||
JPushPlugin.prototype.getNotification = function (callback) {
|
|
||||||
if(device.platform == "Android") {
|
|
||||||
data=[];
|
|
||||||
this.call_native("getNotification",data,callback);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
JPushPlugin.prototype.setBasicPushNotificationBuilder = function(){
|
JPushPlugin.prototype.setBasicPushNotificationBuilder = function(){
|
||||||
if(device.platform == "Android") {
|
if(device.platform == "Android") {
|
||||||
data=[]
|
data=[]
|
||||||
@@ -113,10 +188,8 @@ JPushPlugin.prototype.setCustomPushNotificationBuilder = function(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
JPushPlugin.prototype.stopPush = function(){
|
JPushPlugin.prototype.stopPush = function(){
|
||||||
if(device.platform == "Android") {
|
data=[];
|
||||||
data=[];
|
this.call_native("stopPush",data,null);
|
||||||
this.call_native("stopPush",data,null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JPushPlugin.prototype.resumePush = function(){
|
JPushPlugin.prototype.resumePush = function(){
|
||||||
@@ -125,8 +198,13 @@ JPushPlugin.prototype.resumePush = function(){
|
|||||||
this.call_native("resumePush",data,null);
|
this.call_native("resumePush",data,null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
JPushPlugin.prototype.setDebugMode = function(mode){
|
||||||
JPushPlugin.prototype.clearAllNoticication = function(){
|
if(device.platform == "Android") {
|
||||||
|
this.call_native("setDebugMode",[mode],null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//setDebugMode
|
||||||
|
JPushPlugin.prototype.clearAllNotification = function(){
|
||||||
if(device.platform == "Android") {
|
if(device.platform == "Android") {
|
||||||
data=[]
|
data=[]
|
||||||
this.call_native("clearAllNotification",data,null);
|
this.call_native("clearAllNotification",data,null);
|
||||||
@@ -153,13 +231,30 @@ JPushPlugin.prototype.init = function(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
JPushPlugin.prototype.setDebugable = function(mode){
|
JPushPlugin.prototype.setDebugMode = function(mode){
|
||||||
if(device.platform == "Android") {
|
if(device.platform == "Android") {
|
||||||
this.call_native("setDebugable",[mode],null);
|
this.call_native("setDebugMode",[mode],null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
JPushPlugin.prototype.addLocalNotification = function(builderId,content,title,notificaitonID,broadcastTime,extras){
|
||||||
|
if(device.platform == "Android") {
|
||||||
|
data=[builderId,content,title,notificaitonID,broadcastTime,extras];
|
||||||
|
this.call_native("addLocalNotification",data,null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
JPushPlugin.prototype.removeLocalNotification = function(notificationID){
|
||||||
|
if(device.platform == "Android") {
|
||||||
|
this.call_native("removeLocalNotification",[notificationID],null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
JPushPlugin.prototype.clearLocalNotifications = function(){
|
||||||
|
if(device.platform == "Android") {
|
||||||
|
data=[]
|
||||||
|
this.call_native("clearLocalNotifications",data,null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//ios single
|
//iOS single
|
||||||
|
|
||||||
|
|
||||||
if(!window.plugins){
|
if(!window.plugins){
|
||||||
|
|||||||
Reference in New Issue
Block a user