我的應用程序有推送通知,我可以在alert中顯示推送通知消息嗎?如何在iOS中顯示推送通知?
注意:當用戶點擊通知時,它將重定向到應用程序頁面,並且通知消失,因此這裏在警報中顯示總通知消息?在iOS應用程序中可能嗎?
我的應用程序有推送通知,我可以在alert中顯示推送通知消息嗎?如何在iOS中顯示推送通知?
注意:當用戶點擊通知時,它將重定向到應用程序頁面,並且通知消失,因此這裏在警報中顯示總通知消息?在iOS應用程序中可能嗎?
(無效)應用:(UIApplication的*)應用 didReceiveRemoteNotification:(的NSDictionary *)USERINFO {
的NSString * stringNotify = [NSString的stringWithFormat:@ 「%@」,[[[USERINFO valueForKey :@「aps」] valueForKey:@「alert」] valueForKey:@「body」]]; NSLog(@「the dictionary is%@」,userInfo);
UIAlertView中* alertView = [[UIAlertView中的alloc] initWithTitle:@ 「通知」 消息 :stringNotify委託:自 cancelButtonTitle:@ 「OK」 otherButtonTitles:無,零]。 [alertView show];
}
我已經創建了一個自定義通知,這將有助於你顯示通知,當您的應用程序是在前臺。 查看以下鏈接iOSForegroundNotification並按照下面的步驟:
SNotificationView.h
和SNotificationView.m
中的文件在您的項目。#import "SNotificationView.h"
添加到您的文件中。您已經將appicon圖片替換/添加到「image.png」。
你必須添加以下行您的AppDelegate文件:
let settings = UIApplication.sharedApplication().currentUserNotificationSettings()
if let aps = userInfo["aps"] as? NSDictionary {
if let alert = aps["alert"] as? NSDictionary {
if let message = alert["message"] as? NSString {
prefs.setObject(message, forKey: "notification")
prefs.synchronize()
print("Message: \(message)\n")
}
} else if let alert = aps["alert"] as? NSString {
// Push notification message is added in NSUserDefault
prefs.setObject(alert, forKey: "notification")
prefs.synchronize()
if (application.applicationState == UIApplicationState.Active) {
if settings?.types & UIUserNotificationType.Alert != nil {
// .Alert is one of the valid options
// If you want to add the badge add the line below
UIApplication.sharedApplication().applicationIconBadgeNumber = UIApplication.sharedApplication().applicationIconBadgeNumber + 1
//Call the custom Notification
NSNotificationCenter.defaultCenter().postNotificationName("remotenotification", object: nil)
}
else
{
// This part will be called if you app notification is set to "NONE"
print("No alert ")
}
}
}
添加以下功能爲您的所有視圖控制器
func callNotification()
{
let prefs = NSUserDefaults.standardUserDefaults()
let alert = prefs.stringForKey("notification")!
SNotificationView.showNotificationViewWithImage(UIImage(named:"image.png"), title: "XcodeProject", message: alert, isAutoHide: true, onTouch: {
SNotificationView.hideNotificationViewOnComplete(nil)
})
}
添加下面一行在你viewDidLoad
NSNotificationCenter.defaultCenter().addObserver(self, selector: "callNotification", name: "remotenotification", object: nil)
希望這可能是有益的
部分我明白你的問題,這是可能的 –
可能重複[獲取推送通知,而應用程序在前臺的iOS(http://stackoverflow.com/questions/14872088/get-push -notification-而應用內功能於前景IOS) – lukya