add platform ios

This commit is contained in:
zhangqinghe 2014-01-20 18:27:31 +08:00
parent 7e8bfe5ee2
commit 69fa06cddd
10 changed files with 234 additions and 76 deletions

View File

@ -14,13 +14,40 @@
<engine name="cordova" version=">=3.0"/>
</engines>
<js-module src="www/JPushPlugin.js" name="JPushPlugin">
<clobbers target="window.plugins.jPushPlugin"/>
</js-module>
<platform name="ios">
<config-file target="config.xml" parent="/*">
<feature name="JPushPlugin">
<param name="ios-package" value="JPushPlugin"/>
</feature>
</config-file>
<header-file src="str/ios/Plugins/JPushPlugin.h"/>
<source-file src="str/ios/Plugins/JPushPlugin.m"/>
<header-file src="str/ios/lib/APService.h" />
<source-file src="str/ios/lib/libPushSDK.a" framework="true" />
<resource-file src="str/ios/PushConfig.plist" />
<framework src="CFNetwork.framework" weak="true" />
<framework src="CoreFoundation.framework" weak="true" />
<framework src="SystemConfiguration.framework" weak="true" />
<framework src="CoreGraphics.framework" weak="true" />
<framework src="Foundation.framework" weak="true" />
<framework src="CoreFoundation.framework" weak="true" />
<framework src="UIKit.framework" weak="true" />
<framework src="CoreTelephony.framework" weak="true" />
</platform>
<!-- android -->
<platform name="android">
<js-module src="www/JPushPlugin.js" name="JPushPlugin">
<clobbers target="window.plugins.jPushPlugin"/>
</js-module>
<config-file target="res/xml/config.xml" parent="/*">
<feature name="JPushPlugin">
<param name="android-package" value="cn.jpush.phonegap.JPushPlugin"/>

BIN
src/ios/.DS_Store vendored Normal file

Binary file not shown.

BIN
src/ios/Plugins/.DS_Store vendored Normal file

Binary file not shown.

View File

@ -0,0 +1,18 @@
//
// PushTalkPlugin.h
// PushTalk
//
// Created by zhangqinghe on 13-12-13.
//
//
#import <Cordova/CDV.h>
@interface JPushPlugin : CDVPlugin{
}
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command;
-(void)setTags:(CDVInvokedUrlCommand*)command;
-(void)setAlias:(CDVInvokedUrlCommand*)command;
@end

View File

@ -0,0 +1,77 @@
//
// PushTalkPlugin.m
// PushTalk
//
// Created by zhangqinghe on 13-12-13.
//
//
#import "JPushPlugin.h"
#import "APService.h"
@implementation JPushPlugin
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command{
NSArray *arguments=command.arguments;
if (!arguments||[arguments count]<2) {
[self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.pushCallback('%@')",@""]];
return ;
}
NSString *tags=[arguments objectAtIndex:0];
NSString *alias=[arguments objectAtIndex:1];
NSArray *arrayTags=[tags componentsSeparatedByString:@","];
// NSArray *tags=[arguments subarrayWithRange:range];
[APService setTags:[NSSet setWithArray:arrayTags]
alias:alias
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
object:self];
//[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
-(void)setTags:(CDVInvokedUrlCommand *)command{
//CDVPluginResult *pluginResult=nil;
NSArray *arguments=[command arguments];
NSString *tags=[arguments objectAtIndex:0];
NSArray *array=[tags componentsSeparatedByString:@","];
[APService setTags:[NSSet setWithArray:array]
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
object:self];
//[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
-(void)setAlias:(CDVInvokedUrlCommand *)command{
CDVPluginResult *pluginResult=nil;
NSArray *arguments=[command arguments];
[APService setAlias:[arguments objectAtIndex:0]
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
object:self];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
-(void)tagsWithAliasCallback:(int)resultCode tags:(NSSet *)tags alias:(NSString *)alias{
NSLog(@"recode is %d tags is %@ alias %@",resultCode,tags,alias);
NSDictionary *dict=[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:resultCode],@"resultCode",
tags==nil?[NSNull null]:[tags allObjects],@"resultTags",
alias==nil?[NSNull null]:alias,@"resultAlias",nil];
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:0 error:&error];
NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
dispatch_async(dispatch_get_main_queue(), ^{
[self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.pushCallback('%@')",jsonString]];
});
}
@end

10
src/ios/PushConfig.plist Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>APP_KEY</key>
<string>7d431e42dfa6a6d693ac2d04</string>
<key>CHANNEL</key>
<string>Subscription</string>
</dict>
</plist>

BIN
src/ios/lib/.DS_Store vendored Normal file

Binary file not shown.

39
src/ios/lib/APService.h Normal file
View File

@ -0,0 +1,39 @@
//
// APService.h
// APService
//
// Created by JPush on 12-8-15.
// Copyright (c) 2012年 HXHG. All rights reserved.
// Version: 1.6.2
#import <Foundation/Foundation.h>
extern NSString * const kAPNetworkDidSetupNotification; // 建立连接
extern NSString * const kAPNetworkDidCloseNotification; // 关闭连接
extern NSString * const kAPNetworkDidRegisterNotification; // 注册成功
extern NSString * const kAPNetworkDidLoginNotification; // 登录成功
extern NSString * const kAPNetworkDidReceiveMessageNotification; // 收到消息(非APNS)
extern NSString * const kAPServiceErrorNotification; // 错误提示
@interface APService : NSObject
// 以下四个接口是必须调用的
+ (void)setupWithOption:(NSDictionary *)launchingOption; // 初始化
+ (void)registerForRemoteNotificationTypes:(int)types; // 注册APNS类型
+ (void)registerDeviceToken:(NSData *)deviceToken; // 向服务器上报Device Token
+ (void)handleRemoteNotification:(NSDictionary *)remoteInfo; // 处理收到的APNS消息向服务器上报收到APNS消息
// 下面的接口是可选的
// 设置标签和(或)别名若参数为nil则忽略若是空对象则清空详情请参考文档http://docs.jpush.cn/pages/viewpage.action?pageId=3309913
+ (void)setTags:(NSSet *)tags alias:(NSString *)alias DEPRECATED_ATTRIBUTE;
+ (void)setTags:(NSSet *)tags alias:(NSString *)alias callbackSelector:(SEL)cbSelector target:(id)theTarget;
+ (void)setTags:(NSSet *)tags alias:(NSString *)alias callbackSelector:(SEL)cbSelector object:(id)theTarget;
+ (void)setTags:(NSSet *)tags callbackSelector:(SEL)cbSelector object:(id)theTarget;
+ (void)setAlias:(NSString *)alias callbackSelector:(SEL)cbSelector object:(id)theTarget;
// 用于过滤出正确可用的tags如果总数量超出最大限制则返回最大数量的靠前的可用tags
+ (NSSet*)filterValidTags:(NSSet*)tags;
+ (NSString *)openUDID; // UDID
@end

BIN
src/ios/lib/libPushSDK.a Normal file

Binary file not shown.

View File

@ -1,82 +1,69 @@
var JPushPlugin = function(){
};
JPushPlugin.prototype.error_callback = function (msg) {
console.log("Javascript Callback Error: " + msg)
JPushPlugin.prototype.call_native = function ( name, args) {
console.log("JPushPlugin.call_native:"+name);
ret = cordova.exec(null,
null,
'JPushPlugin',
name,
args);
return ret;
}
JPushPlugin.prototype.call_native = function (callback, name, args) {
if(arguments.length == 2) {
args = []
}
ret = cordova.exec(
callback,
this.error_callback,
'JPushPlugin',
name,
args);
return ret;
JPushPlugin.prototype.setTagsWithAlias = function (tags,alias) {
console.log("JPushPlugin:setTagsWithAlias");
if(tags==null){
this.setAlias(alias);
return;
}
if(alias==null){
this.setTags(tags);
return;
}
var arrayTagWithAlias=[tags];
arrayTagWithAlias.unshift(alias);
this.call_native( "setTagsWithAlias", arrayTagWithAlias);
}
JPushPlugin.prototype.setTags = function (tags, callback) {
this.call_native(callback, "setTags", [tags])
JPushPlugin.prototype.setTags = function (data) {
console.log("JPushPlugin:setTags");
try{
this.call_native("setTags", [data]);
}
catch(exception){
alert(exception);
}
}
JPushPlugin.prototype.setAlias = function (alias, callback) {
this.call_native(callback, "setAlias", [alias])
JPushPlugin.prototype.setAlias = function (data) {
console.log("JPushPlugin:setAlias");
try{
this.call_native("setAlias", [data]);
}
catch(exception){
alert(exception);
}
}
JPushPlugin.prototype.pushCallback = function (data) {
var strArr = [data]
var str = strArr[0].message
document.getElementById('tarea').value=str
try{
var bToObj=JSON.parse(data);
var code = bToObj.resultCode;
var tags = bToObj.resultTags;
var alias = bToObj.resultAlias;
console.log("JPushPlugin:callBack--code is "+code+" tags is "+tags + " alias is "+alias);
}
catch(exception){
alert(exception);
}
}
JPushPlugin.prototype.getNotification = function (callback) {
this.call_native(callback, "getNotification");
}
JPushPlugin.prototype.setBasicPushNotificationBuilder = function(callback){
this.call_native(callback,"setBasicPushNotificationBuilder");
}
JPushPlugin.prototype.setCustomPushNotificationBuilder = function(callback){
this.call_native(callback,"setCustomPushNotificationBuilder");
}
JPushPlugin.prototype.stopPush = function(callback){
this.call_native(callback,"stopPush");
}
JPushPlugin.prototype.resumePush = function(callback){
this.call_native(callback,"resumePush");
}
JPushPlugin.prototype.clearAllNoticication = function(callback){
this.call_native(callback,"clearAllNotification");
}
JPushPlugin.prototype.setLatestNotificationNum = function(num,callback){
this.call_native(callback,"setLatestNotificationNum",[num]);
}
JPushPlugin.prototype.isPushStopped = function(callback){
this.call_native(callback,"isPushStopped")
}
JPushPlugin.prototype.init = function(callback){
this.call_natvie(callback,"init");
}
JPushPlugin.prototype.setDebugable = function(mode,callback){
this.call_native(callback,"setDebugable",[mode]);
}
if(!window.plugins) {
window.plugins = {};
window.plugins = {};
}
if(!window.plugins.jPushPlugin){
window.plugins.jPushPlugin = new JPushPlugin();
}
window.plugins.jPushPlugin = new JPushPlugin();
}
module.exports = new JPushPlugin();