http://123.321.456.121:8080/test/
我在iOS 10和iPhone中遇到问题。获取推送通知警报两次。请查看以下视频。
我在willPresentNotification和didReceiveNotificationResponse通知委托方法中编写了类似的代码。我在这两种方法中都有任何变化,因为我没有遇到iPad的问题。
我们将不胜感激。
答案 0 :(得分:0)
在iOS 10
中,我们需要在appDelegate UNUserNotificationCenter
方法中调用didFinishLaunchingWithOptions
。
您必须导入UserNotifications.framework
并在UNUserNotificationCenterDelegate
Appdelegate
<强> AppDelegate.h 强>
#import <UIKit/UIKit.h>
#import <UserNotifications/UserNotifications.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate,UNUserNotificationCenterDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if([[[UIDevice currentDevice]systemVersion]floatValue]<10.0)
{
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else
{
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error)
{
if( !error )
{
[[UIApplication sharedApplication] registerForRemoteNotifications];
NSLog( @"Push registration success." );
}
else
{
NSLog( @"Push registration FAILED" );
NSLog( @"ERROR: %@ - %@", error.localizedFailureReason, error.localizedDescription );
NSLog( @"SUGGESTIONS: %@ - %@", error.localizedRecoveryOptions, error.localizedRecoverySuggestion );
}
}];
}
return YES;
}
获取Swift See this
中的信息答案 1 :(得分:0)
我发现了错误。我在两个委托方法中编写相同的代码并获取内容可用:有效负载中的1个参数导致两个方法在前台触发的问题。这导致应用程序为单个推送通知显示两个警报。