button action from OneSignal notification?

如何获取通知警报操作事件处理程序?

  • In AppDelegate.m

    [OneSignal initWithLaunchOptions:launchOptions appId:@"put app ID here." 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"]]; }
  • 链接地址: http://www.djcxy.com/p/67266.html

    上一篇: 如何自定义MKAnnotationView的调出泡泡?

    下一篇: OneSignal通知中的按钮操作?