我在 iOS 10 和 iPhone 中遇到问题。两次获得推送通知警报。请查看以下视频。
我在 willPresentNotification 和 didReceiveNotificationResponse 通知委托(delegate)方法中编写了类似的代码。我在这两种方法中进行代码更改是否有任何更改,因为我在 iPad 中没有遇到问题。
您的帮助将不胜感激。
在iOS 10
中,我们需要在appDelegate didFinishLaunchingWithOptions
方法中调用UNUserNotificationCenter
。
您必须导入UserNotifications.framework
并在Appdelegate
中添加UNUserNotificationCenterDelegate
AppDelegate.h
#import <UIKit/UIKit.h>
#import <UserNotifications/UserNotifications.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate,UNUserNotificationCenterDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
AppDelegate.m
- (BOOL)applicationUIApplication *)application didFinishLaunchingWithOptionsNSDictionary *)launchOptions
{
if([[[UIDevice currentDevice]systemVersion]floatValue]<10.0)
{
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypesUIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else
{
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[center requestAuthorizationWithOptionsUNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error)
{
if( !error )
{
[[UIApplication sharedApplication] registerForRemoteNotifications];
NSLog( @"ush registration success." );
}
else
{
NSLog( @"ush registration FAILED" );
NSLog( @"ERROR: %@ - %@", error.localizedFailureReason, error.localizedDescription );
NSLog( @"SUGGESTIONS: %@ - %@", error.localizedRecoveryOptions, error.localizedRecoverySuggestion );
}
}];
}
return YES;
}
在 Swift 中获取信息 See this
关于iOS 10 在 iPhone 中获得两次推送通知警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40101154/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) | Powered by Discuz! X3.4 |