Ionic Push Notification

ionic push notification issues and solutions

IOS Push Notification

  1. For ios push notification, Must Install cocoapods(https://cocoapods.org/) to use firebase notification
  2. Must install phonegap-plugin-push after run pod setup, so usually do rm -r plugins and do ionic cordova build ios again
  3. For ios notification
    • You must specify SENDER_ID inside config.xml
  4. For ios notification
    • You must need a paid apple account to enable push notification on apple’s developer portal
  5. For ios notification
    • You must generate certificates for dev/prod on apple developer portal’s identifier -> Push Notification selection
  6. For ios notification, if you use Google’s fcm notification
    • You must set up the APNs Certificates(upload .p12 format Certificates) at Firebase Portal Cloud Messaging -> iOS app configuration
    • To generate p12 file, you need to import cert files into your keychain app and export as p12 file.

AWS SNS Configuration

  1. Amazon SNS -> Mobile: Push notifications -> Create Platform application

    • Application name
    • Push notification platform: FCM
    • API key: Google FCM API KEY
  2. Publish Message, Sample message body

    • Android:

      1
      2
      3
      {
      "GCM": "{ \"data\": { \"message\": \"Sample message for Android endpoints\" } }"
      }
    • IOS:

      1
      2
      3
      {
      "GCM": "{ \"notification\": { \"text\": \"test message\",\"body\":\"body\",\"sound\":\"default\",\"badge\":\"2\"} }"
      }

Register device to sns and publish push notification

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import boto3

sns = boto3.client('sns')
sns_platform_application_arn = os.environ['SNS_PLATFORM_APPLICATION_ARN']
# regitser endpoint
sns_endpoint_response = sns.create_platform_endpoint(
PlatformApplicationArn=sns_platform_application_arn,
Token=token
)
endpoint_arn = sns_endpoint_response['EndpointArn']

# publish message
try:
platform = 'android'
if platform == 'android':
data = { "data": { "message": "push notification message"}}
elif platform == 'ios':
data = { "notification": {
"text": "push notification message",
"sound": "default",
"badge": 2
}}
publish_result = sns.publish(
TargetArn=arn,
MessageStructure='json',
Message=json.dumps({'GCM': json.dumps(data)})
)
except Exception as e:
print(e)