- 在AppDelegate.m中
[OneSignal initWithLaunchOptions:launchOptions appId:@“将应用程序ID放在这里 . ” 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]];
}
} settings:@{kOSSettingsKeyInFocusDisplayOption : @(OSNotificationDisplayTypeNotification), kOSSettingsKeyAutoPrompt : @YES}];
[OneSignal IdsAvailable:^(NSString *userId, NSString *pushToken) {
if(pushToken) {
NSLog(@"Received push token - %@", pushToken);
NSLog(@"User ID - %@", userId);
}
}];
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@“http://www.google.com”]]; }