1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
import
UIKit
@UIApplicationMain
class
AppDelegate
:
UIResponder
,
UIApplicationDelegate
{
var
window:
UIWindow
?
func
application(_ application:
UIApplication
,
didFinishLaunchingWithOptions
launchOptions: [
UIApplicationLaunchOptionsKey
:
Any
]?) ->
Bool
{
//通知类型(这里将声音、消息、提醒角标都给加上)
let
userSettings =
UIUserNotificationSettings
(types: [.alert, .badge, .sound],
categories:
nil
)
if
((
UIDevice
.current.systemVersion
as
NSString
).floatValue >= 8.0) {
//可以添加自定义categories
JPUSHService
.register(forRemoteNotificationTypes: userSettings.types.rawValue,
categories:
nil
)
}
else
{
//categories 必须为nil
JPUSHService
.register(forRemoteNotificationTypes: userSettings.types.rawValue,
categories:
nil
)
}
// 启动JPushSDK
JPUSHService
.setup(withOption:
nil
, appKey:
"7b96331738ea713195698fd"
,
channel:
"Publish Channel"
, apsForProduction:
false
)
return
true
}
func
application(_ application:
UIApplication
,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken:
Data
) {
//注册 DeviceToken
JPUSHService
.registerDeviceToken(deviceToken)
}
func
application(_ application:
UIApplication
,
didReceiveRemoteNotification userInfo: [
AnyHashable
:
Any
],
fetchCompletionHandler
completionHandler:
@escaping
(
UIBackgroundFetchResult
) ->
Void
) {
//增加IOS 7的支持
JPUSHService
.handleRemoteNotification(userInfo)
completionHandler(
UIBackgroundFetchResult
.newData)
}
func
application(_ application:
UIApplication
,
didFailToRegisterForRemoteNotificationsWithError error:
Error
) {
//可选
NSLog
(
"did Fail To Register For Remote Notifications With Error: \(error)"
)
}
//..........
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
import
UIKit
class
ViewController
:
UIViewController
{
@IBOutlet
weak
var
switch1:
UISwitch
!
@IBOutlet
weak
var
switch2:
UISwitch
!
@IBOutlet
weak
var
switch3:
UISwitch
!
@IBOutlet
weak
var
textView:
UITextView
!
override
func
viewDidLoad() {
super
.viewDidLoad()
}
//按钮点击
@IBAction
func
btnTouchUp(sender:
AnyObject
) {
//获取标签
var
tags =
Set
<
NSObject
>()
if
switch1.on {
tags.insert(
"movie"
)
}
if
switch2.on {
tags.insert(
"music"
)
}
if
switch3.on {
tags.insert(
"game"
)
}
//注册标签
JPUSHService
.setTags(tags,
callbackSelector: #selector(tagsAliasCallBack(_:tags:alias:)),
object:
self
)
}
//标签注册回调
func
tagsAliasCallBack(resCode:
CInt
, tags:
NSSet
, alias:
NSString
) {
textView.text =
"响应结果:\(resCode)"
}
override
func
didReceiveMemoryWarning() {
super
.didReceiveMemoryWarning()
}
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
//引入代码
require
'JPush/autoload.php'
;
use
JPush
\
Client
as
JPush
;
if
(isset($_POST[
"message"
])){
//初始化
$app_key =
"7b528333738ec729165798fd"
;
$master_secret =
"32da4e2c36957b247a2c9828"
;
$client =
new
JPush
($app_key, $master_secret);
//将逗号隔开的字符串拆分成标签数组
$tags = explode(
','
, $_POST[
"tags"
]);
//简单的推送样例
$result = $client->push()
->setPlatform(
'ios'
,
'android'
)
->addTag($tags)
->setNotificationAlert($_POST[
"message"
])
->options(array(
"apns_production"
=>
true
//true表示发送到生产环境(默认值),false为开发环境
))
->send();
echo
'Result='
. json_encode($result);
}
?>
标签:
消息:
|