cowbell / cordova-plugin-geofence

Geofencing plugin for cordova
Apache License 2.0
264 stars 318 forks source link

app crashed after adding plugin #222

Open bigbossmaher opened 7 years ago

bigbossmaher commented 7 years ago

my app is no longuer working after adding the plugin to my app cordova plugin add https://github.com/cowbell/cordova-plugin-geofence how to solve it ?

Quixotical commented 7 years ago

to further elaborate on this issue, I added the plugin following the directions on the repo Creating Ionic 2 application:

1.) cordova plugin add cordova-plugin-geofence 2.) add <preference name="UseLegacySwiftLanguageVersion" value="true" /> to config.xml file 3.)

Since iOS 10 it's mandatory to add a NSLocationAlwaysUsageDescription and NSLocationWhenInUseUsageDescription entries in the info.plist.

verified that these were added to my plist.

Expectation: I build the app and it compiles successfully. Result: Failure due to swift needing upgrade with error message:

“Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choose a Swift version or use the Build Settings editor to configure the build setting directly.

4.) Go into xCode & find edit > convert > To Current Swift Syntax 5.) Attempt to build project

Expectation: Builds Successfully Result: Build failure because of 48 errors in the newly converted swift code

/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:350:48: error: expected expression in list of expressions
            return JSONIndex(dictionaryIndex: <#T##Dictionary corresponding to your index##Dictionary<<#Key: Hashable#>, Any>#>.index(after: self.dictionaryIndex!))
                                               ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:350:103: error: editor placeholder in source file
            return JSONIndex(dictionaryIndex: <#T##Dictionary corresponding to your index##Dictionary<<#Key: Hashable#>, Any>#>.index(after: self.dictionaryIndex!))
                                                                                                      ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:350:126: error: expected expression after operator
            return JSONIndex(dictionaryIndex: <#T##Dictionary corresponding to your index##Dictionary<<#Key: Hashable#>, Any>#>.index(after: self.dictionaryIndex!))
                                                                                                                             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:233:58: warning: 'Indexable' is deprecated: it will be removed in Swift 4.0.  Please use 'Collection' instead
extension JSON : Swift.Collection, Swift.Sequence, Swift.Indexable {
                                                         ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:806:1: error: inheritance from non-protocol type 'Bool'
extension JSON: Swift.Bool {
^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:417:40: error: use of undeclared type 'DictionaryGenerator'
    fileprivate var dictionayGenerate: DictionaryGenerator<String, AnyObject>?
                                       ^~~~~~~~~~~~~~~~~~~
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:233:1: error: type 'JSON' does not conform to protocol '_IndexableBase'
extension JSON : Swift.Collection, Swift.Sequence, Swift.Indexable {
^
Swift._IndexableBase:110:17: note: protocol requires function 'index(after:)' with type '(JSON.Index) -> JSON.Index'; do you want to add a stub?
    public func index(after i: Self.Index) -> Self.Index
                ^
Swift._Indexable:37:17: note: candidate has non-matching type '<Self> (Self.Index, offsetBy: Self.IndexDistance) -> Self.Index' [with _Element = JSONGenerator.Element, SubSequence = Slice<JSON>]
    public func index(_ i: Self.Index, offsetBy n: Self
.IndexDistance) -> Self.Index
                ^
Swift._Indexable:79:17: note: candidate has non-matching type '<Self> (Self.Index, offsetBy: Self.IndexDistance, limitedBy: Self.Index) -> Self.Index?' [with _Element = JSONGenerator.Element, SubSequence = Slice<JSON>]
    public func index(_ i: Self.Index, offsetBy n: Self.IndexDistance, limitedBy limit: Self.Index) -> Self.Index?
                ^
Swift.Collection:22:17: note: candidate has non-matching type '<Self> (of: Self.Iterator.Element) -> Self.Index?' [with _Element = JSONGenerator.Element, SubSequence = Slice<JSON>]
    public func index(of element: Self.Iterator.Element) -> Self.Index?
                ^
Swift.Collection:24:17: note: candidate throws, but protocol does not allow it
    public func index(where predicate: (Self.Iterator.Element) throws -> Bool) rethrows -> Self.Index?
                ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:968:65: warning: left side of nil coalescing operator '??' has non-optional type 'AnyObject', so the right side is never used
            self.object = newValue?.absoluteString as AnyObject ?? NSNull()
                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^~~~~~~~~~~

/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:116:59: error: 'jsonObject' produces 'Any', not the expected contextual result type 'AnyObject'
            let object: AnyObject = try JSONSerialization.jsonObject(with: data, options: opt)
                                                          ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:145:14: error: cannot invoke 'JSON.init' with an argument list of type '([AnyObject])'
        self.init(jsonArray.map { $0.object })
             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:145:14: note: overloads for 'JSON.init' exist with these partially matching parameter lists: (AnyObject), ([JSON]), ([String : JSON])
        self.init(jsonArray.map { $0.object })
             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:160:14: error: cannot invoke 'JSON.init' with an argument list of type '([String : AnyObject])'
        self.init(dictionary)
             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:160:14: note: overloads for 'JSON.init' exist with these partially matching parameter lists: (AnyObject), ([JSON]), ([String : JSON])
        self.init(dictionary)
             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:434:47: error: '++' is unavailable: it has been removed in Swift 3
                return (String(self.arrayIndex++), JSON(o))
                                              ^~
Swift.++:3:21: note: '++' has been explicitly marked unavailable here
postfix public func ++(x: inout Int) -> Int
                    ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:598:14: error: cannot invoke 'JSON.init' with an argument list of type '(StringLiteralType)'
        self.init(value)
             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:598:14: note: overloads for 'JSON.init' exist with these partially matching parameter lists: (AnyObject), ([JSON]), ([String : JSON])
        self.init(value)
             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:602:14: error: cannot invoke 'JSON.init' with an argument list of type '(StringLiteralType)'
        self.init(value)
             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:602:14: note: overloads for 'JSON.init' exist with these partially matching parameter lists: (AnyObject), ([JSON]), ([String : JSON])
        self.init(value)
             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:606:14: error: cannot invoke 'JSON.init' with an argument list of type '(StringLiteralType)'
        self.init(value)
             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:606:14: note: overloads for 'JSON.init' exist with these partially matching parameter lists: (AnyObject), ([JSON]), ([String : JSON])
        self.init(value)
             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:613:14: error: cannot invoke 'JSON.init' with an argument list of type '(IntegerLiteralType)'
        self.init(value)
             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:613:14: note: overloads for 'JSON.init' exist with these partially matching parameter lists: (AnyObject), ([JSON]), ([String : JSON])
        self.init(value)
             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:620:14: error: cannot invoke 'JSON.init' with an argument list of type '(BooleanLiteralType)'
        self.init(value)
             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:620:14: note: overloads for 'JSON.init' exist with these partially matching parameter lists: (AnyObject), ([JSON]), ([String : JSON])
        self.init(value)
             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:627:14: error: cannot invoke 'JSON.init' with an argument list of type '(FloatLiteralType)'
        self.init(value)
             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:627:14: note: overloads for 'JSON.init' exist with these partially matching parameter lists: (AnyObject), ([JSON]), ([String : JSON])
        self.init(value)
             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:634:14: error: cannot invoke 'JSON.init' with an argument list of type '([String : AnyObject])'
        self.init(elements.reduce([String : AnyObject]()){(dictionary: [String : AnyObject], element:(String, AnyObject)) -> [String : AnyObject] in
             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:634:14: note: overloads for 'JSON.init' exist with these partially matching parameter lists: (AnyObject), ([JSON]), ([String : JSON])
        self.init(elements.reduce([String : AnyObject]()){(dictionary: [String : AnyObject], element:(String, AnyObject)) -> [String : AnyObject] in
             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:645:14: error: cannot invoke 'JSON.init' with an argument list of type '([AnyObject])'
        self.init(elements)
             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:645:14: note: overloads for 'JSON.init' exist with these partially matching parameter lists
: (AnyObject), ([JSON]), ([String : JSON])
        self.init(elements)
             ^
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:680:62: error: default argument value of type 'String.Encoding' cannot be converted to type 'UInt'
    public func rawString(_ encoding: UInt = String.Encoding.utf8, options opt: JSONSerialization.WritingOptions = .prettyPrinted) -> String? {
                                             ~~~~~~~~~~~~~~~~^~~~
/platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift:685:65: warning: conditional downcast from 'NSString?' to 'String' is a bridging conversion; did you mean to use 'as'?
                return NSString(data: data, encoding: encoding) as? String
                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^~~ ~~~~~~
                                                                as        ?

** BUILD FAILED **

The following build commands failed:

    CompileSwift normal x86_64 /platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/GeofencePlugin.swift
    CompileSwift normal x86_64 /platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftData.swift
    CompileSwift normal x86_64 /platforms/ios/CatchABreak/Plugins/cordova-plugin-geofence/SwiftyJson.swift
    CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler
(4 failures)

Error: Error code 65 for command: xcodebuild with args: -xcconfig,/platforms/ios/cordova/build-debug.xcconfig,-workspace,CatchABreak.xcworkspace,-scheme,CatchABreak,-configuration,Debug,-sdk,iphonesimulator,-destination,platform=iOS Simulator,name=iPhone 5s,build,CONFIGURATION_BUILD_DIR=/platforms/ios/build/emulator,SHARED_PRECOMPS_DIR=/platforms/ios/build/sharedpch

I don't think I missed any steps in getting this set up, and I really have no idea how to fix all these issues with the swift code. Any help/guidance would be greatly appreciated

JFernandoGomez commented 7 years ago

+1 same error as @Quixotical

Quixotical commented 7 years ago

@JFernandoGomez hey! OK so I got it working! I am not sure what step I had not followed to the letter but I was able to resolve the issue like they had suggested in issue https://github.com/cowbell/cordova-plugin-geofence/issues/215

Basically I went to all 3 of the links, GeoFence.swift, SwiftyJson.swift, & SwiftData.swift and copied that code into the 3 files with the errors in my project.(be careful because the link they have for SwiftyJson takes you to SwiftData) This resolved the issues & now I can build successfully. Give that a shot and if you have any questions/issues let me know and we can try to figure it out!