(void)更新: - 方法在ios10中无法使用cordova-local-notification

时间:2017-04-17 06:52:53

标签: cordova cordova-plugins ios10 uilocalnotification

计划和取消工作正常,但下载完成后更新通知对我不起作用。用插件编写的代码是我不熟悉的目标C.非常感谢任何人对这个问题的帮助。

错误:由于未捕获的异常终止应用程序' NSInvalidArgumentException',原因:' - [UNNotificationRequest userInfo]:无法识别的选择器发送到实例0x174030f40

我只是在这里输入带有文件名的相关代码。请仔细阅读并告诉我它为什么不起作用。如需完整参考,您可以转到下面的插件链接。

插件:https://github.com/katzer/cordova-plugin-local-notifications#ios10

文件:file.service.js //调用插件的更新功能

    window.cordova.plugins.notification.local.update({
            id: optionsId,
            title: attachmentObject.Name,
            text: 'Download completed successfully.'/*,
            icon: 'res://icon.png'
            ,smallIcon:'res://icon.png'*/
          },function (result) {
            console.log('from local notification update ' + result); 
          // coming Null
          });

文件:APPLocalNotification.h

            #import <Foundation/Foundation.h>
            #import <Cordova/CDVPlugin.h>

            @import UserNotifications;

            @interface APPLocalNotification : CDVPlugin <UNUserNotificationCenterDelegate>

            // Execute all queued events
            - (void) deviceready:(CDVInvokedUrlCommand*)command;

            // Inform if the app has the permission to show 
   notifications
            - (void) hasPermission:(CDVInvokedUrlCommand*)command;
            // Register permission to show notifications
            - (void) registerPermission:
   (CDVInvokedUrlCommand*)command;

            // Schedule set of notifications
            - (void) schedule:(CDVInvokedUrlCommand*)command;
            // Update set of notifications
            - (void) update:(CDVInvokedUrlCommand*)command;
            // Cancel set of notifications
            - (void) cancel:(CDVInvokedUrlCommand*)command;
            // Cancel all notifications
            - (void) cancelAll:(CDVInvokedUrlCommand*)command;
            // Clear set of notifications
            - (void) clear:(CDVInvokedUrlCommand*)command;
            // Clear all notifications
            - (void) clearAll:(CDVInvokedUrlCommand*)command;

            // If a notification with an ID is present
            - (void) isPresent:(CDVInvokedUrlCommand*)command;
            // If a notification with an ID is scheduled
            - (void) isScheduled:(CDVInvokedUrlCommand*)command;
            // If a notification with an ID is triggered
            - (void) isTriggered:(CDVInvokedUrlCommand*)command;

            // List all ids from all local notifications
            - (void) getAllIds:(CDVInvokedUrlCommand*)command;
            // List all ids from all pending notifications
            - (void) getScheduledIds:(CDVInvokedUrlCommand*)command;
            // List all ids from all triggered notifications
            - (void) getTriggeredIds:(CDVInvokedUrlCommand*)command;

            // Propertys for given local notification
            - (void) getSingle:(CDVInvokedUrlCommand*)command;
            // Propertya for given scheduled notification
            - (void) getSingleScheduled:
     (CDVInvokedUrlCommand*)command;
            // Propertys for given triggered notification
            - (void) getSingleTriggered:
   (CDVInvokedUrlCommand*)command;

            // Property list for given local notifications
            - (void) getAll:(CDVInvokedUrlCommand*)command;
            // Property list for given scheduled notifications
            - (void) getScheduled:(CDVInvokedUrlCommand*)command;
            // Property list for given triggered notifications
            - (void) getTriggered:(CDVInvokedUrlCommand*)command;

            @end

文件:APPLocalNotification.m

                 #import "APPLocalNotification.h"
                #import "APPLocalNotificationOptions.h"
                #import "UNUserNotificationCenter+APPLocalNotification.h"
                #import "UNNotificationRequest+APPLocalNotification.h"
                #import "UNMutableNotificationContent+APPLocalNotification.h"

                #import "APPLocalNotificationOptions.ios9.h"
                #import "UIApplication+APPLocalNotification.ios9.h"
                #import "UILocalNotification+APPLocalNotification.ios9.h"

                - (void) update:(CDVInvokedUrlCommand*)command
                {
                    NSArray* notifications = command.arguments;
                    [self.commandDelegate runInBackground:^{
                        if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10.0")) {
                            NSLog(@" Ramesh Entered : IOS 10");          
                            for (NSDictionary* options in notifications) {
                                NSNumber* id = [options objectForKey:@"id"];
                                UNNotificationRequest* notification;
                                notification = [self.center getNotificationWithId:id];
                                NSLog(@" Ramesh getnotification : IOS 10 ");
                                NSLog(@"%@",notification);               
                                if (!notification)
                                    continue;
                                        // [self updateNotification:[notification copy] withOptions:options];
                                        // [self fireEvent:@"update" notification:notification];
                                        //                if (notifications.count > 1) {
                                        //   [NSThread sleepForTimeInterval:0.01];
                                        // }
                            }
                        } else {
                            for (NSDictionary* options in notifications) {
                                NSNumber* id = [options objectForKey:@"id"];
                                UILocalNotification* notification;
                                notification = [self.app localNotificationWithId:id];
                                if (!notification)
                                    continue;
                                [self updateLocalNotification:[notification copy]
                                                withOptions:options];
                                [self fireEvent:@"update" localnotification:notification];
                                if (notifications.count > 1) {
                                    [NSThread sleepForTimeInterval:0.01];
                                }
                            }
                        }

                        [self execCallback:command];
                    }];
                }

                - (void) updateNotification:(UILocalNotification*)notification
                                withOptions:(NSDictionary*)newOptions
                {
                    NSMutableDictionary* options = [notification.userInfo mutableCopy];
                    [options addEntriesFromDictionary:newOptions];
                    [options setObject:[NSDate date] forKey:@"updatedAt"];

                //    notification = [[UILocalNotification alloc]
                //                    initWithOptions:options];

                //    [self scheduleLocalNotification:notification];
                }

部分代码在(void)更新方法中进行了注释,该更新方法是在ios10中更新通知。取消注释会因错误而崩溃应用程序。

0 个答案:

没有答案