Просмотр исходного кода

Fix duplicate symbol _UIApplicationRegisterUserNotificationSettings

Sebastián Katzer 10 лет назад
Родитель
Сommit
ecb12b555b

+ 8 - 3
plugin.xml

@@ -59,9 +59,6 @@
             </feature>
         </config-file>
 
-        <header-file src="src/ios/AppDelegate+APPLocalNotification.h" />
-        <source-file src="src/ios/AppDelegate+APPLocalNotification.m" />
-
         <header-file src="src/ios/APPLocalNotification.h" />
         <source-file src="src/ios/APPLocalNotification.m" />
 
@@ -74,6 +71,14 @@
         <header-file src="src/ios/UILocalNotification+APPLocalNotification.h" />
         <source-file src="src/ios/UILocalNotification+APPLocalNotification.m" />
 
+        <hook
+            type="after_platform_add"
+            src="scripts/ios/didRegisterUserNotificationSettings.js" />
+
+        <hook
+            type="after_plugin_install"
+            src="scripts/ios/didRegisterUserNotificationSettings.js" />
+
     </platform>
 
     <!-- android -->

+ 119 - 0
scripts/ios/didRegisterUserNotificationSettings.js

@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2013-2015 by appPlant UG. All rights reserved.
+ *
+ * @APPPLANT_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apache License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://opensource.org/licenses/Apache-2.0/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPPLANT_LICENSE_HEADER_END@
+ */
+
+
+// Hook inserts the UIApplicationRegisterUserNotificationSettings constant
+// and the didRegisterUserNotificationSettings method to AppDelegate.
+
+
+var fs = require('fs'),
+    path = require('path'),
+    rootdir = process.argv[2];
+
+if (!rootdir)
+    return;
+
+module.exports = function (context) {
+
+    var cordova_util = context.requireCordovaModule('cordova-lib/src/cordova/util'),
+        ConfigParser = context.requireCordovaModule('cordova-lib/src/configparser/ConfigParser'),
+        platforms = context.requireCordovaModule('cordova-lib/src/cordova/platforms'),
+        projectRoot = cordova_util.isCordova(),
+        xml = cordova_util.projectConfig(projectRoot),
+        cfg = new ConfigParser(xml);
+
+    /**
+     * The absolute path for the file.
+     *
+     * @param {String} platform
+     *      The name of the platform like 'ios'.
+     * @param {String} relPath
+     *      The relative path from the platform root directory.
+     *
+     * @return String
+     */
+    function getAbsPath(platform, relPath) {
+        var platform_path = path.join(projectRoot, 'platforms', platform),
+            parser = new platforms[platform].parser(platform_path);
+
+        return path.join(parser.cordovaproj, relPath);
+    }
+
+    /**
+     * Replaces a string with another one in a file.
+     *
+     * @param {String} path
+     *      Absolute or relative file path from cordova root project.
+     * @param {String} to_replace
+     *      The string to replace.
+     * @param {String}
+     *      The string to replace with.
+     */
+    function replace (path, to_replace, replace_with) {
+        var data = fs.readFileSync(path, 'utf8'),
+            result;
+
+        if (data.indexOf(replace_with) > -1)
+            return;
+
+        result = data.replace(new RegExp(to_replace, 'g'), replace_with);
+
+        fs.writeFileSync(path, result, 'utf8');
+    }
+
+    // Absolute paths for AppDelegate's header and member
+    var h_path = getAbsPath('ios', 'Classes/AppDelegate.h'),
+        m_path = getAbsPath('ios', 'Classes/AppDelegate.m');
+
+    // Decleration of UIApplicationRegisterUserNotificationSettings
+    var h_UIApplicationRegisterUserNotificationSettings =
+        "extern NSString* const UIApplicationRegisterUserNotificationSettings;\n";
+
+    // Implementation of UIApplicationRegisterUserNotificationSettings
+    var m_UIApplicationRegisterUserNotificationSettings =
+        "NSString* const UIApplicationRegisterUserNotificationSettings = @\"UIApplicationRegisterUserNotificationSettings\";\n";
+
+    // Implementation for didRegisterUserNotificationSettings
+    var didRegisterUserNotificationSettings =
+        "#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000\n" +
+        "\n" +
+        "- (void)                    application:(UIApplication*)application\n" +
+        "    didRegisterUserNotificationSettings:(UIUserNotificationSettings*)settings\n" +
+        "{\n" +
+        "    NSNotificationCenter* center = [NSNotificationCenter\n" +
+        "                                    defaultCenter];\n" +
+        "\n" +
+        "    // re-post (broadcast)\n" +
+        "    [center postNotificationName:UIApplicationRegisterUserNotificationSettings\n" +
+        "                          object:settings];\n" +
+        "}\n" +
+        "#endif\n";
+
+    // Inserts the constant decleration
+    replace(h_path, '@interface AppDelegate', h_UIApplicationRegisterUserNotificationSettings + "\n@interface AppDelegate");
+    // Inserts the constant implementation
+    replace(m_path, '@implementation AppDelegate', m_UIApplicationRegisterUserNotificationSettings + "\n@implementation AppDelegate");
+    // Inserts the didRegisterUserNotificationSettings implementation
+    replace(m_path, '@end', didRegisterUserNotificationSettings + "\n@end");
+
+};

+ 1 - 1
src/ios/APPLocalNotification.m

@@ -21,9 +21,9 @@
  * @APPPLANT_LICENSE_HEADER_END@
  */
 
+#import "AppDelegate.h"
 #import "APPLocalNotification.h"
 #import "APPLocalNotificationOptions.h"
-#import "AppDelegate+APPLocalNotification.h"
 #import "UIApplication+APPLocalNotification.h"
 #import "UILocalNotification+APPLocalNotification.h"
 

+ 0 - 38
src/ios/AppDelegate+APPLocalNotification.h

@@ -1,38 +0,0 @@
-/*
- * Copyright (c) 2013-2015 by appPlant UG. All rights reserved.
- *
- * @APPPLANT_LICENSE_HEADER_START@
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apache License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://opensource.org/licenses/Apache-2.0/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- *
- * @APPPLANT_LICENSE_HEADER_END@
- */
-
-#import "AppDelegate.h"
-
-#import <Availability.h>
-
-extern NSString* const UIApplicationRegisterUserNotificationSettings;
-
-@interface AppDelegate (APPLocalNotification)
-
-#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
-// Tells the delegate what types of notifications may be used
-- (void)                    application:(UIApplication*)application
-    didRegisterUserNotificationSettings:(UIUserNotificationSettings*)settings;
-#endif
-
-@end

+ 0 - 49
src/ios/AppDelegate+APPLocalNotification.m

@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 2013-2015 by appPlant UG. All rights reserved.
- *
- * @APPPLANT_LICENSE_HEADER_START@
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apache License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://opensource.org/licenses/Apache-2.0/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- *
- * @APPPLANT_LICENSE_HEADER_END@
- */
-
-#import "AppDelegate+APPLocalNotification.h"
-
-#import <Availability.h>
-
-NSString* const UIApplicationRegisterUserNotificationSettings = @"UIApplicationRegisterUserNotificationSettings";
-
-@implementation AppDelegate (APPLocalNotification)
-
-#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
-/**
- * Tells the delegate what types of notifications may be used
- * to get the user’s attention.
- */
-- (void)                    application:(UIApplication*)application
-    didRegisterUserNotificationSettings:(UIUserNotificationSettings*)settings
-{
-    NSNotificationCenter* center = [NSNotificationCenter
-                                    defaultCenter];
-
-    // re-post (broadcast)
-    [center postNotificationName:UIApplicationRegisterUserNotificationSettings
-                          object:settings];
-}
-#endif
-
-@end