摘要:本文将带你了解IOS开发入门swift3.0 集成极光推送(v2.2)iOS10.0最新写法,希望本文对大家学IOS有所帮助。
本文将带你了解IOS开发入门swift3.0 集成极光推送(v2.2)iOS10.0最新写法,希望本文对大家学IOS有所帮助。
////
AppDelegate.swift// 1120-jiguang//// Created by targetcloud on
2016/11/20.// Copyright © 2016年 targetcloud. All rights
reserved.// import UIKit @UIApplicationMainclass AppDelegate:
UIResponder, UIApplicationDelegate { var window:
UIWindow? func application(_ application:
UIApplication, didFinishLaunchingWithOptions launchOptions:
[UIApplicationLaunchOptionsKey: Any]?) -> Bool { if
#available(iOS 10.0,
*){ let
entiity =
JPUSHRegisterEntity() entiity.types
= Int(UNAuthorizationOptions.alert.rawValue
| UNAuthorizationOptions.badge.rawValue
| UNAuthorizationOptions.sound.rawValue) JPUSHService.register(forRemoteNotificationConfig:
entiity, delegate: self) }
else if #available(iOS 8.0, *) { let
types = UIUserNotificationType.badge.rawValue
| UIUserNotificationType.sound.rawValue
| UIUserNotificationType.alert.rawValue JPUSHService.register(forRemoteNotificationTypes:
types, categories: nil) }else
{ let
type = UIRemoteNotificationType.badge.rawValue
| UIRemoteNotificationType.sound.rawValue
| UIRemoteNotificationType.alert.rawValue JPUSHService.register(forRemoteNotificationTypes:
type, categories:
nil) } JPUSHService.setup(withOption:
launchOptions, appKey:
"4adfb75ea2e6b055ccb04891", channel:
"app
store", apsForProduction:
false) return
true } func application(_
application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken
deviceToken: Data)
{ JPUSHService.registerDeviceToken(deviceToken) } func
application(_ application: UIApplication, didReceiveRemoteNotification
userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler:
@escaping (UIBackgroundFetchResult) -> Void)
{ JPUSHService.handleRemoteNotification(userInfo) completionHandler(.newData) } func
application(_ application: UIApplication, didReceiveRemoteNotification
userInfo: [AnyHashable: Any])
{ JPUSHService.handleRemoteNotification(userInfo) } } extension
AppDelegate : JPUSHRegisterDelegate{ func jpushNotificationCenter(_
center: UNUserNotificationCenter!, willPresent notification: UNNotification!,
withCompletionHandler completionHandler: ((Int) -> Void)!)
{ print(">JPUSHRegisterDelegate
jpushNotificationCenter
willPresent"); let
userInfo =
notification.request.content.userInfo if
(notification.request.trigger?.isKind(of: UNPushNotificationTrigger.self))!{ JPUSHService.handleRemoteNotification(userInfo) } completionHandler(Int(UNAuthorizationOptions.alert.rawValue))//
需要执行这个方法,选择是否提醒用户,有Badge、Sound、Alert三种类型可以选择设置 } func
jpushNotificationCenter(_ center: UNUserNotificationCenter!, didReceive
response: UNNotificationResponse!, withCompletionHandler completionHandler:
(() -> Void)!)
{ print(">JPUSHRegisterDelegate
jpushNotificationCenter
didReceive"); let
userInfo =
response.notification.request.content.userInfo if
(response.notification.request.trigger?.isKind(of:
UNPushNotificationTrigger.self))!{ JPUSHService.handleRemoteNotification(userInfo) } completionHandler() }}/* 2016-11-20
20:45:37.712478 1120-jiguang[553:149164] | JPUSH | I -
[JPUSHService] --------------------------- JPush Log
---------------------------- --------------------JPush SDK
Version:2.2.0--build:44---------- -----------------AppKey:4adfb75ea2e6b055ccb04891---------------- ---------------------------------------------------------------- 2016-11-20
20:45:37.740351 1120-jiguang[553:149164] | JPUSH | I -
[JPUSHClientController] Action - setup 2016-11-20 20:45:37.940545
1120-jiguang[553:149163] | JPUSH | W - [JPUSHLocationInfoController]
reportWifiInfo not exist 2016-11-20 20:45:38.367587
1120-jiguang[553:149163] | JPUSH | I - [JPUSHSessionController]
connecting with coreAddr 118.145.3.74,port 7001 2016-11-20 20:45:38.578520
1120-jiguang[553:149166] | JPUSH | I - [JPUSHLogin] ----- login
result
----- uid:7719140901 registrationID:161a3797c80a709c926 2016-11-20
20:45:38.590008 1120-jiguang[553:149163] | JPUSH | I -
[JPUSHDeviceTokenReport] try to upload device
token:04a359d9ce5f988618db2072602c0884e8f3dcf04747ae8a20863c20eb0a8a6d 2016-11-20
20:45:39.669897 1120-jiguang[553:149162] | JPUSH | I -
[JPUSHDeviceTokenReport] upload device token success */
集成步骤补充
1、下载包,拖包中的Lib到工程中
2、设置依赖包
3、根据需要加入ATS
4、建立桥接文件并配置桥接文件
//// bridge.h//
1120-jiguang//// Created by targetcloud on 2016/11/20.//
Copyright © 2016年 targetcloud. All rights reserved.// #ifndef
bridge_h#define bridge_h// 引入JPush功能所需头文件#import "JPUSHService.h"//
iOS10注册APNs所需头文件#ifdef NSFoundationVersionNumber_iOS_9_x_Max#import
5、打开相关Capabilities
6、写代码(见上)
7、真机运行
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标移动开发之IOS频道!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号