2016-06-23 5 views
0

Ich folgte this tutorial, um Schaltflächen auf einer Push-Benachrichtigung anzuzeigen.
Schaltflächen werden durch den Aufruf registerNotification in didFinishLaunchingWithOptions registriert.
In einigen Fällen muss ich jedoch eine einfache Benachrichtigung ohne Tasten anzeigen. Wie können Sie die Schaltflächen für verschiedene Benachrichtigungen anzeigen/ausblenden?Interaktive Push-Benachrichtigungen - Schaltflächen ausblenden/anzeigen

+0

notification.category = "Wert" als interaktive Meldung handeln. Ohne notification.category = "value" handelt es sich um eine normale lokale Benachrichtigung. –

Antwort

2

Ich hoffe, das hilft Ihnen.

 
Parameter Description. 
    userInfo --> dictionary value for user needs. 
    title --> notitification Title. 
    fireDate --> trigger notification date and time. 
    Interactive -> pass flag to set Interactive or normal notification. 
-(void)setLocalnotfication:(NSDictionary *)userInfo title:(NSString *)title date:(NSDate *)fireDate Interactive : (BOOL)flag { 
    UILocalNotification *notification = [[UILocalNotification alloc] init]; 
    notification.fireDate = fireDate; 
    notification.alertBody = title; 
    notification.timeZone = [NSTimeZone defaultTimeZone]; 
    notification.soundName = UILocalNotificationDefaultSoundName; 
    if(flag) notification.category = @"Category name"; 
    if([userInfo isKindOfClass:[NSDictionary class]]) notification.userInfo = userInfo; 
    [[UIApplication sharedApplication] scheduleLocalNotification:notification]; 

} 

ich diesen Code verwenden es zu schaffen.

und raschere

func setLocalnotfication(userInfo: [NSObject : AnyObject], title: String, date fireDate: NSDate, Interactive flag: Bool) { 
    var notification: UILocalNotification = UILocalNotification() 
    notification.fireDate = fireDate 
    notification.alertBody = title 
    notification.timeZone = NSTimeZone.defaultTimeZone() 
    notification.soundName = UILocalNotificationDefaultSoundName 
    if flag { 
    notification.category = NCI 
    } 
    if (userInfo is NSDictionary.self) { 
    notification.userInfo = userInfo 
    } 
    UIApplication.sharedApplication().scheduleLocalNotification(notification) 
} 

Refer the Website

3

Für eine andere Art von interaktiven Benachrichtigung ohne Schaltfläche Hinzufügen müssen Sie die UIUserNotificationSettings aktualisieren.

Erstellen Sie eine neue Benachrichtigung Kategorie UIMutableUserNotificationCategory ohne Taste:

UIMutableUserNotificationCategory *newNotificationCategory = [[UIMutableUserNotificationCategory alloc] init]; 
newNotificationCategory.identifier = @"no_button_id"; 

Dann fügen Sie diese neue Kategorie der bestehenden UIUserNotificationSettings:

NSMutableArray *arrNewCategories = [NSMutableArray new]; 
    UIUserNotificationSettings *oldSettings = [[UIApplication sharedApplication]currentUserNotificationSettings]; 
    for (UIMutableUserNotificationCategory *oldCategory in oldSettings.categories) 
    { 
     if (![oldCategory.identifier isEqualToString:newNotificationCategory.identifier]) 
      [arrNewCategories addObject:oldCategory]; 
    } 
    [arrNewCategories addObject:newNotificationCategory]; 

    UIUserNotificationType notificationType = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert; 
    UIUserNotificationSettings *newSettings = [UIUserNotificationSettings settingsForTypes:notificationType categories:[NSSet setWithArray:arrNewCategories]]; 

    [[UIApplication sharedApplication] registerUserNotificationSettings:newSettings]; 

nur sicherstellen, dass die Kennung newNotificationCategory Spiele mit Ihrem UILocalNotification-Kategorie, in der Sie keine Schaltflächen benötigen.

planen Sie dann die Meldung:

UILocalNotification* localNotification = [[UILocalNotification alloc] init]; 
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:afireDate]; 
localNotification.alertBody = @"alert body text"; 
localNotification.category = @"no_button_id"; // Same as category identifier 
localNotification.timeZone = [NSTimeZone systemTimeZone]; 
localNotification.soundName = SOUND_FILE; 
localNotification.repeatInterval = 0; 
[[UIApplication sharedApplication]scheduleLocalNotification:localNotification]; 
+0

Das ist der richtige Weg! Dank bro – iTSangar