简体   繁体   中英

ios 6: push notifications

I'm following this tutorial for creating my first push notification, I followed it step by step everything went great up to the point that I'm running the application on my device I don't get the alert "MyApp" would like to send you push notifications and I'm not seeing myApp in settings --> notification center

I've added like the tutorial said the following code in appdelegate.m:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{     
    // Let the device know we want to receive push notifications
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
     (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}

but when I'm trying to find out which types of push notifications are enabled using this line of code in my first viewDidLoad

UIRemoteNotificationType enabledTypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];

I'm getting UIRemoteNotificationTypeNone

Any Ideas?

You have to make sure your app (in developer portal) is setup for Push notifications;

  1. Goto Apple Developer Portal
  2. Goto identifiers
  3. Select App ID's
  4. Select your app and Check that you have setup Push Notifications

If you have enabled Push Notifications for your app, you will need to regenerate your Provisioning Profile so it will include the Push Certificate details. Also insure you have the Dev certificate for the Push Notifications in your keychain

If you haven't enabled Push Notifications for your app, you will need to create a Push Certificate for Development and Production. After you have created (and installed the Push Certificate in your Keychain) you will need to regenerate your Provisioning Profile so it includes the Push Certificate details.

Remove your old Provisioning file and install your new one you should get the alert to allow pushNotifications

These are the steps that solved my problem (although I have no clue why the problem was happening in the first place)

  1. In XCode go to Window-->Organizer-->Devices on the right pannel choose provisioning profiles --> select your provisioning right click delete.
  2. In build settings make sure your code signing identity is set to iphone developer and not specific provision
  3. Close XCode
  4. In finder go to ~/Library/MobileDevice/Provisioning Profiles --> delete or relocate the existing provisioning (be careful if you have more than one project)
  5. Open the terminal and delete the mobileprovision file if you stil have it.
  6. Go to https://developer.apple.com/account/ios/profile/profileList.action -->provision profiles-->all download again your mobileprovision file
  7. copy your mobileprovision file into ~/Library/MobileDevice/Provisioning Profiles
  8. Open XCode add your mobileprovision directly in the XCode organizer
  9. build and run your application
  10. smile I finally see the allert and the didRegisterForRemoteNotificationsWithDeviceToken function was called :)

Note : the viewDidLoad with the line UIRemoteNotificationType enabledTypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes]; stil returns UIRemoteNotificationTypeNone I'm guessing in a race condition with everything being async it's being called before the notification is being set.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM