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
Antwort
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)
}
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];
Das ist der richtige Weg! Dank bro – iTSangar
- 1. Interaktive ListView
- 2. Interaktive Weltkarte
- 3. Interaktive Webcam
- 4. Erstellen von Schaltflächen mit Schaltflächen
- 5. traceback() für interaktive und nicht interaktive R-Sitzungen
- 6. Git Interaktive Zusammenführung?
- 7. eine interaktive Anmeldesitzung
- 8. Interaktive Alternative zum Punkt?
- 9. Interaktive Karten in Wp7
- 10. Automation - Interaktive Dienste Erkennung
- 11. Interaktive .NET-Charting-Tools?
- 12. Interaktive Batch-Datei
- 13. Interaktive Architektur-Diagramm-Werkzeuge
- 14. Erstellen interaktive Rubin Konsolenanwendung
- 15. Nicht interaktive GIT-Verwendung
- 16. interaktive Kurve Zeichnung
- 17. F # interaktive und Leistungsprofiler
- 18. Interaktive Weltkarte - Vorschläge?
- 19. Python interaktive CLI-Anwendung?
- 20. Interaktive Website Prototyping
- 21. Javascript basierte interaktive Kartenanwendung
- 22. mvc Frage, interaktive Objekte
- 23. Online Interaktive Konsolen
- 24. Redirect Python interaktive Hilfe()
- 25. Interaktive SSH-Eingabeaufforderungen verhindern
- 26. Interaktive Karten mit Javascript
- 27. Windows interaktive Benachrichtigungen
- 28. Interaktive R-Sitzung erzwingen
- 29. Interaktive Textfelder mit Fabric.js
- 30. Interaktive Eingabeaufforderung mit thor
notification.category = "Wert" als interaktive Meldung handeln. Ohne notification.category = "value" handelt es sich um eine normale lokale Benachrichtigung. –