|
phonegap极光推送插件 jpush-phonegap-plugin 适用于phonegap3.0+消息推送
github地址:https://github.com/jpush/jpush-phonegap-plugin
JPush PhoneGap Plugin
创建项目
1.cordova create 文件夹名字 包名 应用名字
cordova create Myproj com.myproj.jpush MyTestProj
2.添加平台
cd Myproj :不进入项目会出现[RangeError:Maximum call stack size exceeded]
cordova platform add android
cordova platform add ios
Android使用PhoneGap/Cordova CLI自动安装
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"/>
3.在 $JPUSH_PLUGIN_DIR/src/android/JPushPlugin.java 文件 import your.package.name.R 替换为在Portal上注册该应用的包名,例如(com.thi.pushtest)
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
1.添加监听系统事件,相应地调用 JPush SDK 提供的 API 来实现功能
- (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];
}
|
|