Last active
November 10, 2016 08:06
-
-
Save jkasten2/a2716a76cd4dfbafb0e969da908e0250 to your computer and use it in GitHub Desktop.
OneSignal2.2.2_Swizzle_testing
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
/** | |
* Modified MIT License | |
* | |
* Copyright 2016 OneSignal | |
* | |
* Permission is hereby granted, free of charge, to any person obtaining a copy | |
* of this software and associated documentation files (the "Software"), to deal | |
* in the Software without restriction, including without limitation the rights | |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
* copies of the Software, and to permit persons to whom the Software is | |
* furnished to do so, subject to the following conditions: | |
* | |
* 1. The above copyright notice and this permission notice shall be included in | |
* all copies or substantial portions of the Software. | |
* | |
* 2. All copies of substantial portions of the Software may only be used in connection | |
* with services provided by OneSignal. | |
* | |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
* THE SOFTWARE. | |
*/ | |
#import "AppDelegate.h" | |
#import <OneSignal/OneSignal.h> | |
#import <objc/runtime.h> | |
@implementation AppDelegate | |
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions { | |
// Eanble logging to help debug issues. visualLevel will show alert dialog boxes. | |
[OneSignal setLogLevel:ONE_S_LL_VERBOSE visualLevel:ONE_S_LL_INFO]; | |
[OneSignal initWithLaunchOptions:launchOptions appId:@"b2f7f966-d8cc-11e4-bed1-df8f05be55ba" handleNotificationReceived:^(OSNotification *notification) { | |
NSLog(@"Received Notification - %@", notification.payload.notificationID); | |
} handleNotificationAction:^(OSNotificationOpenedResult *result) { | |
// This block gets called when the user reacts to a notification received | |
OSNotificationPayload* payload = result.notification.payload; | |
NSString* messageTitle = @"OneSignal Example"; | |
NSString* fullMessage = [payload.body copy]; | |
if (payload.additionalData) { | |
if(payload.title) | |
messageTitle = payload.title; | |
if (result.action.actionID) | |
fullMessage = [fullMessage stringByAppendingString:[NSString stringWithFormat:@"\nPressed ButtonId:%@", result.action.actionID]]; | |
} | |
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:messageTitle | |
message:fullMessage | |
delegate:self | |
cancelButtonTitle:@"Close" | |
otherButtonTitles:nil, nil]; | |
[alertView show]; | |
} settings:@{kOSSettingsKeyInFocusDisplayOption : @(OSNotificationDisplayTypeNotification), kOSSettingsKeyAutoPrompt : @NO}]; | |
[OneSignal IdsAvailable:^(NSString *userId, NSString *pushToken) { | |
if(pushToken) { | |
NSLog(@"Received push token - %@", pushToken); | |
NSLog(@"User ID - %@", userId); | |
} | |
}]; | |
/* | |
// iOS 10 ONLY - Add category for the OSContentExtension | |
// Make sure to add UserNotifications framework in the Linked Frameworks & Libraries. | |
[[UNUserNotificationCenter currentNotificationCenter] getNotificationCategoriesWithCompletionHandler:^(NSSet<UNNotificationCategory *> * _Nonnull categories) { | |
UNNotificationAction* myAction = [UNNotificationAction actionWithIdentifier:@"action0" title:@"Hit Me!" options:UNNotificationActionOptionForeground]; | |
UNNotificationCategory* myCategory = [UNNotificationCategory categoryWithIdentifier:@"myOSContentCategory" actions:@[myAction] intentIdentifiers:@[] options:UNNotificationCategoryOptionCustomDismissAction]; | |
NSSet* mySet = [[NSSet alloc] initWithArray:@[myCategory]]; | |
//Add existing cateogories | |
mySet = [mySet setByAddingObjectsFromSet:categories]; | |
[[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:mySet]; | |
}]; | |
*/ | |
return YES; | |
} | |
- (void)applicationDidEnterBackground:(UIApplication *)application { | |
// [AppDelegate localNotifTest]; | |
[AppDelegate localNotifTestWithTextInput]; | |
} | |
+ (void) localNotifTest { | |
UILocalNotification *notification = [[UILocalNotification alloc] init]; | |
notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:0]; | |
notification.alertBody = @"This is local notification!"; | |
notification.timeZone = [NSTimeZone defaultTimeZone]; | |
notification.soundName = UILocalNotificationDefaultSoundName; | |
notification.applicationIconBadgeNumber = 10; | |
[[UIApplication sharedApplication] scheduleLocalNotification:notification]; | |
} | |
+ (void) localNotifTestWithTextInput { | |
UIMutableUserNotificationAction *action1; | |
action1 = [[UIMutableUserNotificationAction alloc] init]; | |
[action1 setTitle:@"Test1"]; | |
[action1 setIdentifier:@"id1"]; | |
[action1 setBehavior:UIUserNotificationActionBehaviorTextInput]; | |
UIMutableUserNotificationAction *action2; | |
action2 = [[UIMutableUserNotificationAction alloc] init]; | |
[action2 setTitle:@"Test2"]; | |
[action2 setIdentifier:@"id2"]; | |
[action2 setBehavior:UIUserNotificationActionBehaviorDefault]; | |
UIMutableUserNotificationCategory* actionCategory; | |
actionCategory = [[UIMutableUserNotificationCategory alloc] init]; | |
[actionCategory setIdentifier:@"testId"]; | |
[actionCategory setActions:@[action1, action2] forContext:UIUserNotificationActionContextDefault]; | |
NSSet *categories = [NSSet setWithObject:actionCategory]; | |
UIUserNotificationType types = (UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge); | |
UIUserNotificationSettings* settings; | |
settings = [UIUserNotificationSettings settingsForTypes:types categories:categories]; | |
[[UIApplication sharedApplication] registerUserNotificationSettings:settings]; | |
UILocalNotification *notification = [[UILocalNotification alloc] init]; | |
notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:0]; | |
notification.alertBody = @"This is local notification with Text INPUT!"; | |
notification.timeZone = [NSTimeZone defaultTimeZone]; | |
notification.soundName = UILocalNotificationDefaultSoundName; | |
notification.applicationIconBadgeNumber = 10; | |
notification.category = @"testId"; | |
[[UIApplication sharedApplication] scheduleLocalNotification:notification]; | |
} | |
// From iOS 9 device | |
- (void)application:(UIApplication *)application | |
didReceiveLocalNotification:(UILocalNotification *)notification { | |
NSLog(@"application:didReceiveLocalNotification: %@", notification.alertBody); | |
[AppDelegate printObject:notification asClass:UILocalNotification.class]; | |
} | |
// Local - Button - With TextInput | |
- (void)application:(UIApplication *)application | |
handleActionWithIdentifier:(NSString *)identifier | |
forLocalNotification:(UILocalNotification *)notification | |
withResponseInfo:(NSDictionary *)responseInfo | |
completionHandler:(void (^)())completionHandler { | |
NSLog(@"application:handleActionWithIdentifier:forLocalNotification:withResponseInfo:completionHandler: %@", responseInfo); | |
// UIUserNotificationActionResponseTypedTextKey | |
completionHandler(); | |
} | |
// Local - Button | |
- (void)application:(UIApplication *)application | |
handleActionWithIdentifier:(NSString *)identifier | |
forLocalNotification:(UILocalNotification *)notification | |
completionHandler:(void (^)())completionHandler { | |
NSLog(@"application:handleActionWithIdentifier:forLocalNotification:completionHandler: %@", identifier); | |
completionHandler(); | |
} | |
// Remote - Button | |
- (void)application:(UIApplication *)application | |
handleActionWithIdentifier:(NSString *)identifier | |
forRemoteNotification:(NSDictionary *)userInfo | |
completionHandler:(void (^)())completionHandler { | |
NSLog(@"application:handleActionWithIdentifier:forRemoteNotification:completionHandler: %@", identifier); | |
completionHandler(); | |
} | |
// Remote - Button - With TextInput | |
- (void)application:(UIApplication *)application | |
handleActionWithIdentifier:(NSString *)identifier | |
forRemoteNotification:(NSDictionary *)userInfo | |
withResponseInfo:(NSDictionary *)responseInfo | |
completionHandler:(void (^)())completionHandler { | |
NSLog(@"application:handleActionWithIdentifier:forRemoteNotification:withResponseInfo:completionHandler: %@", responseInfo); | |
completionHandler(); | |
} | |
// Remote | |
- (void)application:(UIApplication *)application | |
didReceiveRemoteNotification:(NSDictionary *)userInfo | |
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler { | |
NSLog(@"application:didReceiveRemoteNotification:fetchCompletionHandler: %@", userInfo); | |
completionHandler(nil); | |
} | |
+ (void)printObject:(NSObject*)aObj asClass:(Class)clazz { | |
if (!clazz) | |
clazz = [aObj class]; | |
NSLog(@"HEReE %@", aObj); | |
NSLog(@"HEReE@: %@", [aObj class]); | |
unsigned int cProperties = 0; | |
objc_property_t *props = class_copyPropertyList(clazz, &cProperties); | |
NSLog(@"cProperties: %d", cProperties); | |
for(int i = 0; i < cProperties; i++) { | |
NSString *name = [NSString stringWithUTF8String:property_getName(props[i])]; | |
NSLog(@"%@ = %@", name, [aObj valueForKey:name]); | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment