AWSPushManager Class Reference
Inherits from | NSObject |
---|---|
Declared in | AWSPushManager.h AWSPushManager.m |
Overview
The Push Manager registers the app on the device with Apple Push Notification Service (APNS) and registers the resulting device token in Amazon SNS. The result of this registration process is an Amazon SNS Endpoint ARN, which can be used to send push notifications directly to a specific device. The Push Manager also manages Amazon SNS topic subscriptions, allowing the app to subscribe to Amazon SNS topics, which let you target groups of devices with push notifications. Requires the AWSSNS framework of AWSiOSSDK.
enabled
Indicates if PushManager
is enabled or disabled.
@property (nonatomic, readonly, getter=isEnabled) BOOL enabled
Declared In
AWSPushManager.h
deviceToken
The device token returned by iOS.
@property (nonatomic, readonly, nullable) NSString *deviceToken
Declared In
AWSPushManager.h
endpointARN
The application platform endpoint ARN for Amazon SNS.
@property (nonatomic, readonly, nullable) NSString *endpointARN
Declared In
AWSPushManager.h
platformARN
The application platform ARN for the app.
@property (nonatomic, readonly, nullable) NSString *platformARN
Declared In
AWSPushManager.h
topicARNs
A list of topic ARNs selected during project configuraiton on AWS Mobile Hub from the Info.plist
file.
If a custom helper client is used, it would contain the topic ARNs specified in AWSPushManagerConfiguration object.
@property (nonatomic, readonly, nullable) NSArray<NSString*> *topicARNs
Declared In
AWSPushManager.h
topics
The list of PushTopic
.
@property (nonatomic, readonly) NSArray<AWSPushTopic*> *topics
Declared In
AWSPushManager.h
delegate
The delegate for receiving PushManager
and PushTopic
events.
@property (nonatomic, weak) id<AWSPushManagerDelegate,AWSPushTopicDelegate> delegate
Declared In
AWSPushManager.h
+ defaultPushManager
Returns the default Push Manager singleton instance configured using the information provided in Info.plist
file.
+ (instancetype)defaultPushManager
Discussion
Swift
let pushManager = AWSPushManager.defaultPushManager()
Objective-C
AWSPushManager *pushManager = [AWSPushManager defaultPushManager];
Declared In
AWSPushManager.h
+ registerPushManagerWithConfiguration:forKey:
Creates a helper client for AWSPushManager
for specified configuration with mentioned key.
Use this method only if you require a helper client with specific configuration.
+ (void)registerPushManagerWithConfiguration:(AWSPushManagerConfiguration *)pushManagerConfiguration forKey:(NSString *)key
Parameters
pushManagerConfiguration |
AWSPushManagerConfiguration object for the manager. |
---|---|
key |
A string to identify the helper client. |
Discussion
For example, set the configuration in - application:didFinishLaunchingWithOptions:
Swift
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let credentialProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: "YourIdentityPoolId")
let configuration = AWSServiceConfiguration(region: .USWest2, credentialsProvider: credentialProvider)
AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = configuration
let pushManagerConfiguration = AWSPushManagerConfiguration(snsPlatformARN: "SNS_PLATFORM_ARN")
AWSPushManager.registerPushManagerWithConfiguration(pushManagerConfiguration, forKey: "defaultPushManager")
return true
}
Objective-C
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionUSEast1
identityPoolId:@"YourIdentityPoolId"];
AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSWest2
credentialsProvider:credentialsProvider];
AWSServiceManager.defaultServiceManager.defaultServiceConfiguration = configuration;
AWSPushManagerConfiguration *pushManagerConfiguration = [[AWSPushManager alloc] initWithSNSPlatformARN:@"SNS_PLATFORM_ARN"];
[AWSPushManager registerPushManagerWithConfiguration:pushManagerConfiguration
forKey:@"defaultPushManager"];
return YES;
}
Then call the following to get the helper client:
Swift
let pushmanager = AWSPushManager(forKey: "defaultPushManager")
Objective-C
AWSPushManager *pushmanager = [AWSPushManager pushManagerForKey:@"defaultPushManager"];
Warning: After calling this method, do not modify the configuration object. It may cause unspecified behaviors.
Declared In
AWSPushManager.h
+ PushManagerForKey:NS_SWIFT_NAME:
Retrieves the helper client associated with the key. You need to call + registerPushManagerWithConfiguration:forKey:
before invoking this method. If + registerPushManagerWithConfiguration:forKey:
has not been called in advance or the key does not exist, this method returns nil
.
+ (instancetype)PushManagerForKey:(NSString *)key NS_SWIFT_NAME
Parameters
key |
A string to identify the helper client. |
---|
Return Value
An instance of AWSPushManager for specified key.
Discussion
Swift
let credentialProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: "YourIdentityPoolId")
let configuration = AWSServiceConfiguration(region: .USWest2, credentialsProvider: credentialProvider)
AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = configuration
let pushManagerConfiguration = AWSPushManagerConfiguration(snsPlatformARN: "SNS_PLATFORM_ARN")
AWSPushManager.registerPushManagerWithConfiguration(pushManagerConfiguration, forKey: "defaultPushManager")
Objective-C
AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionUSEast1
identityPoolId:@"YourIdentityPoolId"];
AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSWest2
credentialsProvider:credentialsProvider];
AWSServiceManager.defaultServiceManager.defaultServiceConfiguration = configuration;
AWSPushManagerConfiguration *pushManagerConfiguration = [[AWSPushManager alloc] initWithSNSPlatformARN:@"SNS_PLATFORM_ARN"];
[AWSPushManager registerPushManagerWithConfiguration:pushManagerConfiguration
forKey:@"defaultPushManager"];
Then call the following to get the helper client:
Swift
let Pushmanager = AWSPushManager.PushManager(forKey: "defaultPushManager")
Objective-C
AWSPushManager *Pushmanager = [AWSPushManager PushManagerForKey:@"defaultPushManager"];
Declared In
AWSPushManager.h
+ removePushManagerForKey:
Removes the helper client associated with the key and release it.
+ (void)removePushManagerForKey:(NSString *)key
Parameters
key |
A string to identify the helper client. |
---|
Discussion
Swift
AWSPushManager.removePushManagerForKey("USWest2PushManager")
Objective-C
[AWSPushManager removePushManagerForKey:@"USWest2PushManager"];
Warning: Before calling this method, make sure no method is running on this client.
Declared In
AWSPushManager.h
– registerTopicARNs:
Initializes PushManager
with the list of topic ARNs.
- (void)registerTopicARNs:(NSArray<NSString*> *)topicARNs
Parameters
topicARNs |
A list of topic ARNs from Amazon SNS. It needs to be an |
---|
Declared In
AWSPushManager.h
– topicForTopicARN:
Returns a topic associated with the specified topic ARN.
- (AWSPushTopic *)topicForTopicARN:(NSString *)topicARN
Parameters
topicARN |
A topic ARN from Amazon SNS. |
---|
Return Value
The topic with the specified topic ARN.
Declared In
AWSPushManager.h
– registerForPushNotifications
Initiates the process to enable Push Notifications. When called for the first time, it asks the user for the permission to enable Push Notifications. If the user decline it, it fails to enable Push Notifications.
- (void)registerForPushNotifications
Discussion
On success, it calls - pushManagerDidRegister:
from AWSPushManagerDelegate
.
On failure, it calls - pushManager:didFailToRegisterWithError:
from AWSPushManagerDelegate
.
Declared In
AWSPushManager.h
– disablePushNotifications
Unsubscribes from all subscribed topics, then marks PushManager
as disabled.
- (void)disablePushNotifications
Discussion
On success, it calls - pushManagerDidDisable:
from AWSPushManagerDelegate
.
On failure, it calls - pushManager:didFailToDisableWithError:
from AWSPushManagerDelegate
.
Declared In
AWSPushManager.h
– interceptApplication:didFinishLaunchingWithOptions:
Intercepts the - application:didFinishLaunchingWithOptions:
application delegate.
- (BOOL)interceptApplication:(UIApplication *)application didFinishLaunchingWithOptions:(nullable NSDictionary *)launchOptions
Parameters
application |
Your singleton app object. |
---|---|
launchOptions |
A dictionary indicating the reason the app was launched (if any). The contents of this dictionary may be empty in situations where the user launched the app directly. For information about the possible keys in this dictionary and how to handle them, see Launch Options Keys. |
Declared In
AWSPushManager.h
– interceptApplication:didRegisterForRemoteNotificationsWithDeviceToken:
Intercepts the - application:didRegisterForRemoteNotificationsWithDeviceToken:
application delegate.
- (void)interceptApplication:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
Parameters
application |
The app object that initiated the remote-notification registration process. |
---|---|
deviceToken |
A token that identifies the device to APNs. |
Declared In
AWSPushManager.h
– interceptApplication:didFailToRegisterForRemoteNotificationsWithError:
Intercepts the - application:didFailToRegisterForRemoteNotificationsWithError:
application delegate.
- (void)interceptApplication:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(nullable NSError *)error
Parameters
application |
The app object that initiated the remote-notification registration process. |
---|---|
error |
An |
Declared In
AWSPushManager.h
– interceptApplication:didReceiveRemoteNotification:
Intercepts the - application:didReceiveRemoteNotification:
application delegate.
- (void)interceptApplication:(UIApplication *)application didReceiveRemoteNotification:(nullable NSDictionary *)userInfo
Parameters
application |
The app object that received the remote notification. |
---|---|
userInfo |
A dictionary that contains information related to the remote notification, potentially including a badge number for the app icon, an alert sound, an alert message to display to the user, a notification identifier, and custom data. The provider originates it as a JSON-defined dictionary that iOS converts to an |
Declared In
AWSPushManager.h