자바로 작성된 맞춤 API에서 푸시 알림을받는 iOS 앱에서 사용자가 테이블에 가입하라는 청원을 받거나 거부하도록해야합니다. 나는 기존 코드 기반에서 잠시 후에 작성하고 소프트웨어를 업데이트하고있다.UrbanAirship iOS SDK를 사용하여 푸시 알림을위한 맞춤 메소드
문제는 UrbanAirship이 행동을 근본적으로 수정했으며 더 이상 사용자 지정 알림 상자를 표시 할 수 없다는 것입니다. 다음과 같이 우리의 API에 의해 전송되는
알림 structed됩니다
[Line 227] Received notification: {
"_" = "4f5a2ac1-f337-4181-9c88-70b65d4f501f";
aps = {
alert = "Tu mesa ya est\U00e1 abierta";
};
command = 1;
mode = createCommand;
posType = 2;
restaurant = "Zadia Restaurant";
restaurantId = 1;
}
을 그리고 우리는 다음과 같은 방법은 우리의 AppDelegate에 구현 한 : UAPushNotificationDelegate는 (I 만의 이익을 위해 UAirship에 관련된 코드를 포함하고있어 brevety :
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
if !application.isRegisteredForRemoteNotifications() { //En caso de que no tengamos permisos para push notifications
showWarningDialog()
} else {
UAirship.takeOff()
UAirship.push().userNotificationTypes = ([UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound])
UAirship.push().userPushNotificationsEnabled = true
UAirship.push().pushNotificationDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
}
}
func receivedForegroundNotification(notification: [NSObject : AnyObject], fetchCompletionHandler completionHandler: ((UIBackgroundFetchResult) -> Void)) {
if OurApp.sharedInstance.isCommandTopViewController && notification["type"] != nil && (notification["type"] as! String) == "updateCommand" {
OurApp.sharedInstance.commandController?.refresh()
}
if notification["type"] != nil {
if (notification["type"] as! String).contains("joinRequest") {
showJoinRequestDialog(notification["aps"]!["alert"] as! String, userId: notification["userId"] as! Int)
} else if (notification["type"] as! String).contains("joinResponse") {
let state = notification["state"] as! Int
if state == 1 {
self.preferenceManager.saveCurrentTab(notification["command"] as? String)
self.preferenceManager.saveCurrentRestaurant(notification["restaurant"] as? String)
}
showJoinResponseDialog(notification["aps"]!["alert"] as! String, state: state)
} else if (notification["type"] as! String).contains("promotion") {
showNewPromotionDialog(notification["aps"]!["alert"] as! String, promotion: notification["promotionId"] as! Int)
}
}
// Call the completion handler
completionHandler(UIBackgroundFetchResult.NoData)
}
func launchedFromNotification(notification: [NSObject : AnyObject], fetchCompletionHandler completionHandler: ((UIBackgroundFetchResult) -> Void)) {
if notification["type"] != nil {
if (notification["type"] as! String).contains("joinRequest") {
showJoinRequestDialog(notification["aps"]!["alert"] as! String, userId: notification["userId"] as! Int)
} else if (notification["type"] as! String).contains("joinResponse") {
let state = notification["state"] as! Int
if state == 1 {
self.preferenceManager.saveCurrentTab(notification["command"] as? String)
self.preferenceManager.saveCurrentRestaurant(notification["restaurant"] as? String)
}
showJoinResponseDialog(notification["aps"]!["alert"] as! String, state: state)
}
}
// Call the completion handler
completionHandler(UIBackgroundFetchResult.NoData)
}
func showJoinRequestDialog(message: String, userId: Int) {
let dialog: UIAlertController = UIAlertController(title: NSLocalizedString("Atención", comment:""), message: message + NSLocalizedString("¿Quieres aceptarlo?", comment:""), preferredStyle: .Alert)
dialog.addAction(UIAlertAction(title: NSLocalizedString("Aceptar", comment:""), style: .Default, handler: { action in
let state = 1
self.sendAcceptRequest(userId, state: state)
dialog.dismissViewControllerAnimated(true, completion: nil)
}))
dialog.addAction(UIAlertAction(title: NSLocalizedString("Rechazar", comment:""), style: .Cancel, handler: { action in
let state = 0
self.sendAcceptRequest(userId, state: state)
dialog.dismissViewControllerAnimated(true, completion: nil)
}))
self.window!.rootViewController?.presentViewController(dialog, animated: true, completion: nil)
}
func showJoinResponseDialog(message: String, state: Int) {
let dialog: UIAlertController = UIAlertController(title: NSLocalizedString("Atención", comment:""), message: message, preferredStyle: .Alert)
dialog.addAction(UIAlertAction(title: NSLocalizedString("Aceptar", comment:""), style: .Default, handler: { action in
if(state == 1) {
let mainViewController = OurApp.sharedInstance.mainController
mainViewController.navigateOnSideMenu("command")
}
dialog.dismissViewControllerAnimated(true, completion: nil)
}))
self.window!.rootViewController?.presentViewController(dialog, animated: true, completion: nil)
}
func showNewPromotionDialog(message: String, promotion: Int) {
let dialog: UIAlertController = UIAlertController(title: NSLocalizedString("Atención", comment:""), message: message, preferredStyle: .Alert)
dialog.addAction(UIAlertAction(title: NSLocalizedString("Aceptar", comment:""), style: .Default, handler: { action in
let mainViewController = OurApp.sharedInstance.mainController
mainViewController.navigateOnSideMenu("promotions")
dialog.dismissViewControllerAnimated(true, completion: nil)
}))
self.window!.rootViewController?.presentViewController(dialog, animated: true, completion: nil)
}
func sendAcceptRequest(userId: Int, state: Int) {}
사람이, 최소한의 도시 비행선 SDK와 아이폰 OS (11)의 새 버전이 제대로 작동하려면 코드를 업데이트에 관해서 올바른 방향으로 날 가리 키도록 도움의 손길을 빌려 수 있다면, 크게 감사합니다. 그것.
감사합니다.
알림 페이로드에 "type"은 어디에 있습니까? 알림 : "[type"] –
SDK의 필요에 맞게 알림을 수정할 수는 있지만 문제는 좀 더 깊어 보입니다. 모든 사용자 지정 코드를 제거하고 웹 사이트에서 모든 ios 장치로 알림을 보내면 장치에 대한 알림이 표시됩니다. 지금까지는 좋았지 만, 웹 사이트에서 제공하는 몇 가지 옵션 외에도 알림에 표시된 버튼과 어떻게 상호 작용 하는지를 파악할 수 없었습니다. 따라서 누군가가 수락/거부 버튼과 상호 작용할 수있는 간단한 예제를 제공하고이를 수용 할 수있는 사용자 정의 메소드를 제공 할 수 있다면; 그것은 또한 효과가있을 것입니다. – akseli