我正在尝试让我的应用程序在Xcode 8.0中运行,并且遇到了错误.我知道这个代码在以前版本的swift中运行良好,但我假设在新版本中更改了代码.这是我正在尝试运行的代码:
let settings = UIUserNotificationSettings(forTypes: [.Sound, .Alert, .Badge], categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(settings)
UIApplication.shared().registerForRemoteNotifications()
Run Code Online (Sandbox Code Playgroud)
我得到的错误是"参数标签"(forTypes:,categories :)'与任何可用的重载都不匹配"
是否有一个不同的命令,我可以尝试使其工作?
在iOS 9.3中,该didReceiveRemoteNotification方法在以下两种情况下都会被调用.
1)当收到推送通知时2)当用户通过点击通知启动应用程序时.
但在iOS上10,我注意到,该didReceiveRemoteNotification方法不不,当用户通过点击通知启动应用程序触发.只有在收到通知时才会调用它.因此,在通知启动应用程序后,我无法执行任何进一步操作.
应该解决这个问题?任何的想法?
我已经开发了一个应用程序,因为我实现了推送通知.目前它在苹果商店上市.iOS 9推送工作正常,但iOS 10之后无法正常工作.
代码有什么问题?
我已经使用以下iOS 8,9代码:
UIMutableUserNotificationAction *action1;
action1 = [[UIMutableUserNotificationAction alloc] init];
[action1 setActivationMode:UIUserNotificationActivationModeBackground];
[action1 setTitle:@"REJECT"];
[action1 setIdentifier:NotificationActionOneIdent];
[action1 setDestructive:NO];
[action1 setAuthenticationRequired:NO];
UIMutableUserNotificationAction *action2;
action2 = [[UIMutableUserNotificationAction alloc] init];
[action2 setActivationMode:UIUserNotificationActivationModeBackground];////UIUserNotificationActivationModeBackground
[action2 setTitle:@"ACCEPT"];
[action2 setIdentifier:NotificationActionTwoIdent];
[action2 setDestructive:NO];
[action2 setAuthenticationRequired:NO];
UIMutableUserNotificationCategory *actionCategory;
actionCategory = [[UIMutableUserNotificationCategory alloc] init];
[actionCategory setIdentifier:NotificationCategoryIdent];
[actionCategory setActions:@[action1, action2]
forContext:UIUserNotificationActionContextDefault];
NSSet *categories = [NSSet setWithObject:actionCategory];
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:
UIUserNotificationTypeSound | UIUserNotificationTypeAlert categories:categories];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
Run Code Online (Sandbox Code Playgroud)
委托方法处理:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
//Handle according to app state …Run Code Online (Sandbox Code Playgroud) iphone objective-c apple-push-notifications ios usernotificationsui