ios – 不允许使用arc隐式转换’unsigned long’UIUserNotificationSettings *’

前端之家收集整理的这篇文章主要介绍了ios – 不允许使用arc隐式转换’unsigned long’UIUserNotificationSettings *’前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
iOS 8中的推送通知不起作用.

错误显示

implicit conversion of 'unsigned long 'UIUserNotificationSettings *' is disallowed with arc

码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [application registerUserNotificationSettings:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge)];
    return YES;
}

我正在使用ios 8.0和xcode 6 beta.

解决方法

我从 below from official documentation of iOS 8.开始
  • Apps that use local or push notifications must explicitly register the types of alerts that they display to users by using a UIUserNotificationSettings object. This registration process is separate from the process for registering remote notifications,and users must grant permission to deliver notifications through the requested options.
  • Local and push notifications can include custom actions as part of an alert. Custom actions appear as buttons in the alert. When tapped,your app is notified and asked to perform the corresponding action. Local notifications can also be triggered by interactions with Core Location regions.

还读了

https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIUserNotificationSettings_class/index.html#//apple_ref/occ/cl/UIUserNotificationSettings

https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIApplication_Class/index.html#//apple_ref/occ/instm/UIApplication/registerUserNotificationSettings

所以答案应该是……

/// First register notification setting with settings type like 
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications]; // you can also set here for local notification.

猜你在找的iOS相关文章