How to write Cordova plugin in Swift?

前端 未结 2 1080
不思量自难忘°
不思量自难忘° 2021-01-30 03:32

I converted existing custom plugin to Swift language:

(located under Plugins/CustomPluginInSwift.swift)

import Foundation

class Cu         


        
2条回答
  •  生来不讨喜
    2021-01-30 04:15

    As is mentioned you have to add a bridging-header.h file which contains

    #import 
    

    Also you need to add the bridging header's path in XCode project properties->Build Settings->Objective-C Bridging Header. For example:

    your-app-name/plugins/com.plugin.example/bridging-header.h
    

    Additionally, in order for Objective-C to see the same plugin class name, you need to add an @objc mapping to the class declaration. It can be the same as the swift class name itself, or something different. In this example, "HWPCustomPluginInSwift" will be what Objective-C (and Javascript) will end up seeing:

    @objc(HWPCustomPluginInSwift) class CustomPluginInSwift : CDVPlugin {
    

    and then your feature node in config.xml file should look like this:

    
        
    
    

提交回复
热议问题