如何检查应用程序是否已注册远程通知?

Har*_*pta 1 iphone xcode push-notification apple-push-notifications ios

我尝试在方法中注册远程通知

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Run Code Online (Sandbox Code Playgroud)

因此,当应用程序被推出时,它每次都要求远程注册.据我说它不应该是这样的.如果应用程序已经注册,它应该是.

但我没有找到任何方法来检查思考.

我正在思考还是还有其他方法?

小智 5

试试这个:

+(BOOL)isHaveRegistrationForNotification{

//For ios >= 8.0
if  ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
    return [[UIApplication sharedApplication] isRegisteredForRemoteNotifications];

//For ios < 8
else{ 
    UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
    BOOL deviceEnabled = !(types == UIRemoteNotificationTypeNone);
    return deviceEnabled;
    }
}
Run Code Online (Sandbox Code Playgroud)