(1) Reason
Everything is a ghost of iOS8. If you replace the simulator with iOS7.1 or earlier, you will not have this problem. And now in the iOS8 to achieve badge, alert and sound, etc. need user consent, because these are counted to do notification "notice", in order to prevent some applications to send users "notice" harassment users, so in IOS8, to "notify" The user must agree to the line.
(2) Solve the idea: we judge, if the system version is greater than or equal to 8.0, we will open the application when the user pops up a box prompt said we want to send a notification to you, you agree not? If the user agrees, then we can. And if the system version is less than 8.0, because the default is yes, so we don't need to do anything.
So the question is: How to play a box to the user, and the user agrees to let us send notice?
--First This is the first time the application is opened to load the time to pop up this box, the installation of the app is not unfamiliar to the people. So, it needs to be written in APPDELEGATE.M's Didfinishlaunching method.
--second, we judge the system version, with the IF statement, to obtain the system version, the conversion of nsstring to float can be compared, these are no problem.
In the end, the core is three words in the IF. In general, we define a "notification settings", and then register the "notification settings" in the "User notification Settings", and registered to the "User notification Settings" in the "Notification settings", are used in the box to let users decide whether to accept this notice.
-This "notification setting" is primarily defined as "notification type". We're just badge in this case, but the alert and sound are all types of notifications, so we "superfluous" and all the notification types are included so that we don't need to set up alert and sound one at a time.
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions { float Sysversion=[[uidevice Currentdevice]systemversion].floatvalue; if (sysversion>=8.0) { Uiusernotificationtype Type=uiusernotificationtypebadge | Uiusernotificationtypealert | Uiusernotificationtypesound; Uiusernotificationsettings *setting=[uiusernotificationsettings Settingsfortypes:type Categories:nil]; [[UIApplication sharedapplication]registerusernotificationsettings:setting]; } Override point for customization after application launch. return YES;}
"iOS Dev-71" solution: attempting to badge the application icon but haven ' t received permission from the ...