IOS 8 推送通知检查返回错误的 UIRemoteNotificationType
<p><p>我正在尝试检查我的应用程序的 PushNotifications 是否已启用。 </p>
<p>在 AppDelegate.m 中,我为远程通知注册了应用程序,并在 iPhone (iOS 8) 上的设置中启用了此应用程序的推送通知。</p>
<p>我已经用谷歌搜索了方法:</p>
<pre><code>UIRemoteNotificationType types = [ enabledRemoteNotificationTypes];
BOOL check = [ isRegisteredForRemoteNotifications];
</code></pre>
<p>结果,<em>types = UIRemoteNotificationTypeNone 和 check = NO</em>。</p>
<p>我正在使用 <a href="https://stackoverflow.com/questions/24454033/registerforremotenotificationtypes-is-not-supported-in-ios-8-0-and-later" rel="noreferrer noopener nofollow">code sample</a>注册推送通知申请:</p>
<pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
//-- Set Notification
if ()
{
// iOS 8 Notifications
];
;
}
else
{
// iOS < 8 Notifications
[application registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
}
//--- your custom code
return YES;
}
</code></pre>
<p>这里有什么问题?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我认为您已经找到了解决方案,但以防万一:在 iOS 8 中,已弃用 enabledRemoteNoficationTypes 您应该使用:</p>
<pre><code>if ([ respondsToSelector:@selector(currentUserNotificationSettings)]) {
UIUserNotificationSettings *currentSettings = [ currentUserNotificationSettings];
if (currentSettings.types == UIUserNotificationTypeNone) {}
</code></pre>
<p>最好的</p></p>
<p style="font-size: 20px;">关于IOS 8 推送通知检查返回错误的 UIRemoteNotificationType,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/26379579/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/26379579/
</a>
</p>
页:
[1]