ios-solve the problem of iOS8 and above settings Applicationiconbadgenumber error

Source: Internet
Author: User

Setting Applicationiconbadgenumber in IOS7 is not a problem, but setting applicationiconbadgenumber directly in IOS8 will cause an error. Because you want to set up applicationiconbadgenumber in IOS8, you need the user's authorization, in IOS8, you need to add the following code:

Uiusernotificationsettings *settings = [uiusernotificationsettings settingsfortypes: Uiusernotificationtypebadge Categories:nil]; [[UIApplication sharedapplication] registerusernotificationsettings:settings];

However, if the two sentences are running in the IOS7 system, then the error will be, so you need to first determine the iOS version, the complete code is as follows:

float Version = [[[Uidevice Currentdevice] systemversion] floatvalue];     if 8.0 ) {    *settings = [Uiusernotificationsettings settingsfortypes:uiusernotificationtypebadge Categories:nil];    [[UIApplication sharedapplication] registerusernotificationsettings:settings];}

If you are registering a message push, you need to write this:

float Version = [[[Uidevice Currentdevice] systemversion] floatvalue]; if 8.0 ) {    *settings = [Uiusernotificationsettings settingsfortypes:uiusernotificationtypebadge Categories:nil];    [[UIApplication sharedapplication] registerusernotificationsettings:settings];    [Application registerforremotenotifications];}

ios-solve the problem of iOS8 and above settings Applicationiconbadgenumber error

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.