2016-07-26 7 views
0

Ich habe einen Code erstellt, die Remote-Push-Norification erhalten, dieser Code ist in Ordnung. Jetzt muss ich zwei "Knöpfe" hinzufügen, die nach links ziehen und eine Aktion ausführen. Ich weiß, dass dieser Code unten die AktionRemote-Push-Benachrichtigungen Aktionen

func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forLocalNotification notification: UILocalNotification, completionHandler:() -> Void) { 

    if identifier == "optin1" { 
     //do something 
    } 
    else identifier == "option2" { 
     //do something 
    } 

    completionHandler() 
} 

indetify verwendet wird, aber ich nicht wusste, wie die Schaltflächen erstellen links nach SWIP. Wie kann ich es tun

Das ist mein AppDelegate:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool 
{ 
    // Override point for customization after application launch. 
    let types:UIUserNotificationType = [.Alert, .Sound, .Badge] 


    application.registerForRemoteNotifications() 
    application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: types, categories: nil)) 

    initLocationManager() 

    return true 

} 
func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) { 
    //print(error) 
} 

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) { 

    print(deviceToken) 

} 


func application(application: UIApplication, didReceiveRemoteNotificationuserInfo userInfo: [NSObject : AnyObject]) { 
    print(userInfo) 
} 

Antwort

0

Sie & diesen Code in didFinishLaunchingWithOptions Methode einfügen kopieren:

  1. Erstellen Sie die Aktion

    // NOTFICATION 
    let incrementAction = UIMutableUserNotificationAction() 
    incrementAction.identifier = "HI_ACTION" 
    incrementAction.title = "Hi!" 
    incrementAction.activationMode = UIUserNotificationActivationMode.Background 
    incrementAction.authenticationRequired = false 
    incrementAction.destructive = false 
    
  2. Erstellen Sie die Kategorie

    let counterCategory = UIMutableUserNotificationCategory() 
    counterCategory.identifier = "HELLO_CATEGORY" 
    
  3. assoziierte Aktion und Kategorie

    counterCategory.setActions([incrementAction], 
              forContext: UIUserNotificationActionContext.Default) 
    counterCategory.setActions([incrementAction], 
              forContext: UIUserNotificationActionContext.Minimal) 
    
  4. Registrierung

    let categories = NSSet(object: counterCategory) as! Set<UIUserNotificationCategory> 
    let settings = UIUserNotificationSettings(forTypes: [.Alert, .Sound], categories: categories) 
    UIApplication.sharedApplication().registerUserNotificationSettings(settings) 
    
  5. Der letzte Schritt ist nur für demostration

    let notification = UILocalNotification() 
    notification.alertBody = "Hey!" 
    notification.soundName = UILocalNotificationDefaultSoundName 
    notification.fireDate = NSDate(timeIntervalSinceNow: 5) 
    notification.category = "HELLO_CATEGORY" 
    
    UIApplication.sharedApplication().scheduleLocalNotification(notification) 
    

Wenn die App gestartet wird Sie CMD + L

hier ein link to an example

schieben haben