简体   繁体   中英

iOS Push Notification with GCM

我正在使用 GCM 向 iOS 应用程序发送远程通知,在前台和后台都收到通知,但在后台通知没有在应用程序图标上显示带有声音和徽章编号的横幅,我应该添加哪些字段以及我应该在哪里添加它们

I tried it and it works great. This is how it works:

  • You create app entry at google console.
  • Upload development and production certificated in creation wizard.
  • You have to upload both and follow the steps in docs .

Logic works as follows:

  • We request device token from apns as usual.
  • Then we send that token to gcm service with provided api.
  • Then gcm sends back a another token.
  • We send that token to app server.
  • App server can send notifications using that token.

Cool Features. GCM for iOS has some cool features as:

  • Subscribe to notification based on a particular topic.
  • Ignore others.
  • Send Notification to other devices within the app.

UPDATE: It's Google with a capital G now.

If you want to try google sample app. Just pod try Google .

If you're receiving a remote notification in the background. Likely your content-available = 1 field is already in the json payload, So send your device a local notification and banner to do everything else you want.

let localNotification = UILocalNotification()
localNotification.soundName = UILocalNotificationDefaultSoundName //If you want an alert sound.
localNotification.alertBody = "You received notification" //Put your notification message here
localNotification.applicationIconBadgeNumber += 1 //Change what the badge number should be

UIApplication.sharedApplication().presentLocalNotificationNow(localNotification)

One place to put this code is in a func and call it when you receive the remote notification.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM