【发布时间】:2016-02-17 20:44:10
【问题描述】:
我有一个 swift 应用程序。
我从我的服务器收到 GCM 推送通知。
在 IOS 中,我了解操作系统会负责在我的应用位于后台时显示通知。
当我的应用在 fg 上并且我是显示通知的负责人时,我如何显示推送消息(通知)?
我应该使用本地推送(与远程推送相反)吗?
应用在后台时显示推送的代码是什么?
我知道这段代码处理向用户显示推送
但这不是通知,它只是打开一个警报
func application( application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler handler: (UIBackgroundFetchResult) -> Void) {
print("Notification received: \(userInfo)")
// This works only if the app started the GCM service
GCMService.sharedInstance().appDidReceiveMessage(userInfo);
// Handle the received message
// Invoke the completion handler passing the appropriate UIBackgroundFetchResult value
// [START_EXCLUDE]
NSNotificationCenter.defaultCenter().postNotificationName(messageKey, object: nil,
userInfo: userInfo)
handler(UIBackgroundFetchResult.NoData);
// [END_EXCLUDE]
}
【问题讨论】:
标签: ios xcode swift push-notification