iOS integration of AWS Push finishing

#iOS integrated AWS finishing PushNotification

## integrated AWS

### AWS official website connection
case is Swift version, Demo version of OC provides integrated
1.Profile configure AWS SDK

1
2
3
4
5
6
7
8
9
platform :ios, '9.0'

target :'YOUR-APP-NAME' do
use_frameworks!

pod 'AWSPinpoint', '~> 2.9.0'
# other pods
pod 'AWSMobileClient', '~> 2.9.0'
end

run

1
2
3
4
pod install --repo-update 
```

2. import header file in the AppDelegate:

import AWSCore
import AWSPinpoint
import AWSMobileClient

1
3. initialization, connection AWS server, create objects 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
2
3
4
5
Initialization file access to local awsconfiguration.json successful userState return guest.

### get awsconfiguration.json
[Amplify integration] (https://aws-amplify.github.io/docs/cli/init?sdk=ios)
execute the command

amplify init
amplify push

1
2
3
Awsconfiguration.json into the project to generate 
### upload token
using the created pinpoint upload token

func application(
_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {

    pinpoint!.notificationManager.interceptDidRegisterForRemoteNotifications(
        withDeviceToken: deviceToken)
}

`` `
The AWS background will Endpoint ID generated by the token device, the same function

AWSMobileClient library section of code, written in Swift, if the project is written in OC use, the code needs to be integrated mixed


Download Demo

Original: Big Box  iOS integration of AWS Push finishing


Guess you like

Origin www.cnblogs.com/petewell/p/11614862.html