Apple Push Notification Service doesn't works

2019-08-14 23:46发布

问题:

I have used Apple Push Notification in my apps and it works fine in Adhoc Distribution. I have submitted my apps into the AppStore, But push notification is not working for my apps and received message like "Apple rejected your device tokens". I have used separate .p12 files for development and production builds and uploaded in the Urban Airship.

Note:

But i have used the same application key and application master key for development and production. So that it didn't works for the push notification. If i create a separate keys for distribution and have to use those keys for my distribution builds. So that it will solve the problem. When a creating a application keys in urban airship, then i get the three keys like Application Key, Application Secret and Application Master secret. I have used the application key and Master key in my apps. Is this correct? So please guide me.

Thanks

Regards,
Pugal

回答1:

You need to have:

  1. In Apple's iOS Provisioning Portal
    • App ID's
      • Generate a Development Push SSL Certificate
      • Generate a Production Push SSL Certificate
  2. In Urban Airship Application editor
    • Create an application for development
      • Use the Apps Development Push SSL Certificate in the Apple push certificate entry
      • Copy off the Application Key (development)
      • Copy off the Application Secret (development)
    • Create an application for production
      • Use the Apps Production Push SSL Certificate in the Apple push certificate entry
      • Copy off the Application Key (production)
      • Copy off the Application Secret (production)
  3. Set up Xcode's Code Signing to use the Certificates
  4. I use the following code to set the Urban Airship Keys at compile time based on macros:

    - (void)urbanAirshipTakeoffWithLaunchOptions:(NSDictionary *)launchOptions {
    
    // Init Airship launch options
    NSMutableDictionary *takeOffOptions = [[NSMutableDictionary alloc] init];
    [takeOffOptions setValue:launchOptions forKey:UAirshipTakeOffOptionsLaunchOptionsKey];
    
    // Build the Urban Airship TakeOffOptions
    // Create Airship singleton that's used to talk to Urban Airship servers.
    NSMutableDictionary *airshipConfigOptions = [[NSMutableDictionary alloc] init];
    
    //Set up the Push keys
    NSLog(@"Appdelegate_Pad:didFinishLaunchingWithOptions - TARGET_1");
    [airshipConfigOptions setValue:@"xxx" forKey:@"DEVELOPMENT_APP_KEY"];
    [airshipConfigOptions setValue:@"xxx" forKey:@"DEVELOPMENT_APP_SECRET"];
    [airshipConfigOptions setValue:@"xxx" forKey:@"PRODUCTION_APP_KEY"];
    [airshipConfigOptions setValue:@"xxx" forKey:@"PRODUCTION_APP_SECRET"];
    
    // If CONFIGURATION_Debug is defined, then use the development servers, else use the production servers
    #ifdef CONFIGURATION_Debug
    [airshipConfigOptions setValue:@"NO" forKey:@"APP_STORE_OR_AD_HOC_BUILD"];
    NSLog(@"Using Development Servers at Urban Airship");
    #else
    [airshipConfigOptions setValue:@"YES" forKey:@"APP_STORE_OR_AD_HOC_BUILD"];
    NSLog(@"Using Production Servers at Urban Airship");
    #endif
    
    // Set and start Urban Airship
    [takeOffOptions setValue:airshipConfigOptions forKey:UAirshipTakeOffOptionsAirshipConfigKey];
    [UAirship takeOff:takeOffOptions];
    
    // Register for push notifications
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
                                                                           UIRemoteNotificationTypeSound |
                                                                           UIRemoteNotificationTypeAlert)];
    

    }

One of the best things about this set up is that I can send my beta testers push messages that my production users can not see (i.e.: New beta on TestFlight!).