Created
March 25, 2015 07:08
-
-
Save jkhowland/fc3b952f8a6a0a1f3b5b to your computer and use it in GitHub Desktop.
Push Notification Steps - Sup
This file contains 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
// If you use Parse for Push Notifications, the tutorial on their site is well written: https://www.parse.com/tutorials/ios-push-notifications | |
// 2 - Add Private-Key.h file and set keys | |
static NSString * const ParseApplicationID = @""; | |
static NSString * const ParseClientKey = @""; | |
// 3 - Register for Push from the applicationDidFinishLaunching method | |
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) { | |
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeBadge | |
|UIRemoteNotificationTypeSound | |
|UIRemoteNotificationTypeAlert) categories:nil]; | |
[application registerUserNotificationSettings:settings]; | |
} else { | |
UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound; | |
[application registerForRemoteNotificationTypes:myTypes]; | |
} | |
// 4 - Store device token and handle UI for notifications | |
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { | |
// Store the deviceToken in the current installation and save it to Parse. | |
PFInstallation *currentInstallation = [PFInstallation currentInstallation]; | |
[currentInstallation setDeviceTokenFromData:deviceToken]; | |
[currentInstallation saveInBackground]; | |
} | |
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { | |
[PFPush handlePush:userInfo]; | |
} | |
// We could use usernames as channels. | |
PFInstallation *currentInstallation = [PFInstallation currentInstallation]; | |
[currentInstallation addUniqueObject:[PFUser currentUser].username forKey:@"channels"]; | |
[currentInstallation saveInBackground]; | |
// We could use a query that checks for the username | |
PFQuery *pushQuery = [PFInstallation query]; | |
[pushQuery whereKey:@"username" equalTo:[[SAUsersDataSource sharedInstance] usernameAtIndex:indexPath]]; | |
PFPush *push = [[PFPush alloc] init]; | |
[push setQuery:pushQuery]; | |
[push setMessage:@"Sup"]; | |
[push sendPushInBackground]; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment