#iOS集成AWS整理PushNotification
##集成AWS
###AWS官网连接
案例中是Swift版本,Demo提供了OC版本的集成
1.Profile 中配置AWS SDK
1 | platform :ios, '9.0' |
运行
1 | pod install --repo-update |
import AWSCore
import AWSPinpoint
import AWSMobileClient
1 | 3.初始化,连接AWS服务器,创建Pinpoint对象 |
lass AppDelegate: UIResponder, UIApplicationDelegate {
/** start code copy **/
var pinpoint: AWSPinpoint?
/** end code copy **/
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Other didFinishLaunching code...
/** start code copy **/
// Create AWSMobileClient to connect with AWS
AWSMobileClient.sharedInstance().initialize { (userState, error) in
if let error = error {
print("Error initializing AWSMobileClient: (error.localizedDescription)")
} else if let userState = userState {
print("AWSMobileClient initialized. Current UserState: (userState.rawValue)")
}
}
// Initialize Pinpoint
let pinpointConfiguration = AWSPinpointConfiguration.defaultPinpointConfiguration(launchOptions: launchOptions)
pinpoint = AWSPinpoint(configuration: pinpointConfiguration)
/** end code copy **/
return true
}
}
1 | 初始化会访问本地awsconfiguration.json文件,成功 userState 返回 guest。 |
amplify init
amplify push
1 | 生成awsconfiguration.json放入项目中 |
func application(
_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
pinpoint!.notificationManager.interceptDidRegisterForRemoteNotifications(
withDeviceToken: deviceToken)
}
```
AWS后台会通过device token生成Endpoint ID,功能相同
AWSMobileClient库 部分代码使用Swift编写,如果是使用OC编写的项目,需要进行代码混编的集成