Created
January 25, 2016 18:32
-
-
Save jsbain/8b45a9800f0b37eee6bb to your computer and use it in GitHub Desktop.
notificationplayground.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # coding: utf-8 | |
| #. objc from http://www.thinkandbuild.it/interactive-notifications-with-notification-actions/ | |
| from objc_util import * | |
| UIUserNotificationSetting=ObjCClass('UIUserNotificationSettings') | |
| #UIUserNotificationType=ObjCClass('UIUserNotificationType') | |
| UIMutableUserNotificationCategory=ObjCClass('UIMutableUserNotificationCategory') | |
| UIMutableUserNotificationAction=ObjCClass('UIMutableUserNotificationAction') | |
| UIUserNotificationSettings=ObjCClass('UIUserNotificationSettings') | |
| UILocalNotification=ObjCClass('UILocalNotification') | |
| BG=1 | |
| FG=0 | |
| UIUserNotificationActionContextDefault=0 | |
| UIUserNotificationActionContextMinimal=1 | |
| UIUserNotificationTypeNone = 0, | |
| UIUserNotificationTypeBadge = 1 << 0 | |
| UIUserNotificationTypeSound = 1 << 1 | |
| UIUserNotificationTypeAlert = 1 << 2 | |
| # increment Action | |
| incrementAction = UIMutableUserNotificationAction.new() | |
| incrementAction.identifier = "INCREMENT_ACTION" | |
| incrementAction.title = "Add +1" | |
| incrementAction.activationMode = BG | |
| incrementAction.authenticationRequired = True | |
| incrementAction.destructive = False | |
| #decrement Action | |
| decrementAction = UIMutableUserNotificationAction.new() | |
| decrementAction.identifier = 'DECREMENT_ACTION' | |
| decrementAction.title = "Sub -1" | |
| decrementAction.activationMode = BG | |
| decrementAction.authenticationRequired = True | |
| decrementAction.destructive = False | |
| #// reset Action | |
| resetAction = UIMutableUserNotificationAction.new() | |
| resetAction.identifier = 'RESET_ACTION' | |
| resetAction.title = "Reset" | |
| resetAction.activationMode = FG | |
| resetAction.destructive = True | |
| ##category *********************************************** | |
| #// Category | |
| counterCategory = UIMutableUserNotificationCategory.new() | |
| counterCategory.identifier = 'COUNTER_CATEGORY' | |
| #// A. Set actions for the default context | |
| counterCategory.setActions_forContext_( | |
| [incrementAction, decrementAction, resetAction], UIUserNotificationActionContextDefault) | |
| #// B. Set actions for the minimal context | |
| counterCategory.setActions_forContext_( | |
| [incrementAction, decrementAction], UIUserNotificationActionContextMinimal) | |
| #Registration ***************************************** | |
| types=UIUserNotificationTypeAlert | UIUserNotificationTypeSound | |
| settings = UIUserNotificationSettings.alloc().initWithTypes_categories_(types, NSSet.setWithArray_([counterCategory])) | |
| app=UIApplication.sharedApplication() | |
| app.registerUserNotificationSettings_(settings) | |
| NSDate=ObjCClass('NSDate') | |
| mynotification = UILocalNotification.new() | |
| mynotification.alertBody = 'This is a notification. Swipe for options' | |
| mynotification.fireDate = NSDate.dateWithTimeIntervalSinceNow_(10) | |
| mynotification.category = 'COUNTER_CATEGORY' | |
| #mynotification.repeatInterval = NSCalendarUnit.CalendarUnitMinute | |
| app.scheduleLocalNotification_(mynotification) | |
| #proof of concept... put app in background | |
| import webbrowser | |
| webbrowser.open('safari-http://') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment