Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
galaxy-iOS
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mobile-group
galaxy-iOS
Commits
f2622100
Commit
f2622100
authored
Mar 27, 2024
by
Steven杜宇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
// JPush
parent
17c351ed
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
1 deletion
+68
-1
AppDelegate.swift
galaxy/galaxy/AppDelegate.swift
+3
-0
Applegate(JPush).swift
galaxy/galaxy/Applegate(JPush).swift
+65
-1
No files found.
galaxy/galaxy/AppDelegate.swift
View file @
f2622100
...
...
@@ -27,6 +27,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func
application
(
_
application
:
UIApplication
,
didFinishLaunchingWithOptions
launchOptions
:
[
UIApplication
.
LaunchOptionsKey
:
Any
]?)
->
Bool
{
// JPush服务注册
registerJPushService
()
//全局导航栏、返回事件/手势
setupNavBar
()
...
...
galaxy/galaxy/Applegate(JPush).swift
View file @
f2622100
...
...
@@ -8,6 +8,70 @@
import
UIKit
extension
AppDelegate
{
extension
AppDelegate
:
JPUSHRegisterDelegate
{
// 注册JPush服务
func
registerJPushService
()
{
let
entity
:
JPUSHRegisterEntity
=
JPUSHRegisterEntity
()
entity
.
types
=
Int
(
JPAuthorizationOptions
.
alert
.
rawValue
|
JPAuthorizationOptions
.
badge
.
rawValue
|
JPAuthorizationOptions
.
sound
.
rawValue
|
JPAuthorizationOptions
.
providesAppNotificationSettings
.
rawValue
)
JPUSHService
.
register
(
forRemoteNotificationConfig
:
entity
,
delegate
:
self
)
}
//系统获取Token
func
application
(
_
application
:
UIApplication
,
didRegisterForRemoteNotificationsWithDeviceToken
deviceToken
:
Data
)
{
JPUSHService
.
registerDeviceToken
(
deviceToken
)
}
//获取token 失败
func
application
(
_
application
:
UIApplication
,
didFailToRegisterForRemoteNotificationsWithError
error
:
Error
)
{
//可选
print
(
"did Fail To Register For Remote Notifications With Error:
\(
error
)
"
)
}
//点推送进来执行这个方法
func
application
(
_
application
:
UIApplication
,
didReceiveRemoteNotification
userInfo
:
[
AnyHashable
:
Any
],
fetchCompletionHandler
completionHandler
:
@escaping
(
UIBackgroundFetchResult
)
->
Void
)
{
JPUSHService
.
handleRemoteNotification
(
userInfo
)
completionHandler
(
UIBackgroundFetchResult
.
newData
)
}
//后台进前台
func
applicationDidEnterBackground
(
_
application
:
UIApplication
)
{
//销毁通知红点
UIApplication
.
shared
.
applicationIconBadgeNumber
=
0
JPUSHService
.
setBadge
(
0
)
UNUserNotificationCenter
.
current
()
.
removeAllPendingNotificationRequests
()
}
@available(iOS 10.0, *)
func
jpushNotificationCenter
(
_
center
:
UNUserNotificationCenter
,
willPresent
notification
:
UNNotification
,
withCompletionHandler
completionHandler
:
((
Int
)
->
Void
))
{
let
userInfo
=
notification
.
request
.
content
.
userInfo
if
notification
.
request
.
trigger
is
UNPushNotificationTrigger
{
JPUSHService
.
handleRemoteNotification
(
userInfo
)
}
// 需要执行这个方法,选择是否提醒用户,有Badge、Sound、Alert三种类型可以选择设置
completionHandler
(
Int
(
UNNotificationPresentationOptions
.
alert
.
rawValue
))
}
@available(iOS 10.0, *)
func
jpushNotificationCenter
(
_
center
:
UNUserNotificationCenter
,
didReceive
response
:
UNNotificationResponse
,
withCompletionHandler
completionHandler
:
(()
->
Void
))
{
let
userInfo
=
response
.
notification
.
request
.
content
.
userInfo
if
response
.
notification
.
request
.
trigger
is
UNPushNotificationTrigger
{
JPUSHService
.
handleRemoteNotification
(
userInfo
)
}
// 系统要求执行这个方法
completionHandler
()
}
func
jpushNotificationCenter
(
_
center
:
UNUserNotificationCenter
,
openSettingsFor
notification
:
UNNotification
)
{
}
func
jpushNotificationAuthorization
(
_
status
:
JPAuthorizationStatus
,
withInfo
info
:
[
AnyHashable
:
Any
]?)
{
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment