iOS 10 在 iPhone 中获得两次推送通知警报
<p><p> <a href="/image/KqGe6.png" rel="noreferrer noopener nofollow"><img src="/image/KqGe6.png" alt="enter image description here"/></a> </p>
<p>我在 iOS 10 和 iPhone 中遇到问题。两次获得推送通知警报。请查看以下视频。</p>
<p>我在 willPresentNotification 和 didReceiveNotificationResponse 通知委托(delegate)方法中编写了类似的代码。我在这两种方法中进行代码更改是否有任何更改,因为我在 iPad 中没有遇到问题。 </p>
<p>您的帮助将不胜感激。 </p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>在<code>iOS 10</code>中,我们需要在appDelegate <code>didFinishLaunchingWithOptions</code>方法中调用<code>UNUserNotificationCenter</code>。</p>
<p>您必须导入<code>UserNotifications.framework</code>并在<code>Appdelegate</code>中添加<code>UNUserNotificationCenterDelegate</code></p>
<p><strong>AppDelegate.h</strong></p>
<pre><code>#import <UIKit/UIKit.h>
#import <UserNotifications/UserNotifications.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate,UNUserNotificationCenterDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
</code></pre>
<p>AppDelegate.m</p>
<pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if([[systemVersion]floatValue]<10.0)
{
[ registerUserNotificationSettings:];
[ registerForRemoteNotifications];
}
else
{
UNUserNotificationCenter *center = ;
center.delegate = self;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error)
{
if( !error )
{
[ registerForRemoteNotifications];
NSLog( @"Push registration success." );
}
else
{
NSLog( @"Push registration FAILED" );
NSLog( @"ERROR: %@ - %@", error.localizedFailureReason, error.localizedDescription );
NSLog( @"SUGGESTIONS: %@ - %@", error.localizedRecoveryOptions, error.localizedRecoverySuggestion );
}
}];
}
return YES;
}
</code></pre>
<p>在 Swift 中获取信息 <a href="https://swifting.io/blog/2016/08/22/23-notifications-in-ios-10/" rel="noreferrer noopener nofollow">See this</a> </p></p>
<p style="font-size: 20px;">关于iOS 10 在 iPhone 中获得两次推送通知警报,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/40101154/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/40101154/
</a>
</p>
页:
[1]