NSException 在 iOS 上设置 Tuya SDK 时发生。

huangapple go评论83阅读模式
英文:

NSException occures while setuping Tuya SDK on IOS

问题

I am new on IOS development and I am trying to create lot app using Tuya Smart Life App SDK. I am facing problem when I try to start the app after adding this SDK configure, with appKey and appSecret:

ThingSmartSDK.sharedInstance()?.start(withAppKey: <#your_app_key#>, secretKey: <#your_secret_key#>)

According to the Fast Integration guide this should be placed inside of AppDelegate.m -file, but I have read that this file is not being added to IOS projects automatically any more. (I am using Xcode version '14.3.1')

I have added the AppDelegate class inside of AppNameApp.swift -file and it looks like this:

import SwiftUI
import ThingSmartBaseKit

@main
struct AppNameApp: App {
    
    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
    
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

class AppDelegate: NSObject, UIApplicationDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        ThingSmartSDK.sharedInstance().start(withAppKey: <#your_app_key#>, secretKey: <#your_secret_key#>)
        
        #if DEBUG
        ThingSmartSDK.sharedInstance().debugMode = true
        #else
        #endif
        
        return true
    }
}

Currently I am not seeing any problem messages coming from this in Xcode, but when I try to run the app on simulator it crashes due to uncaught exception of type NSException. Crash message:

2023-07-13 15:26:50.051841+0300 iosAppName[22835:261964] +[NSArray yy_modelArrayWithClass:json:]: unrecognized selector sent to class 0x10c377890
2023-07-13 15:26:50.086746+0300 iosAppName[22835:261964] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSArray yy_modelArrayWithClass:json:]: unrecognized selector sent to class 0x10c377890'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010bf7278b __exceptionPreprocess + 242
    1   libobjc.A.dylib                     0x000000010a1e2b73 objc_exception_throw + 48
    2   CoreFoundation                      0x000000010bf817dd __CFExceptionProem + 0
    3   CoreFoundation                      0x000000010bf76c66 ___forwarding___ + 1443
    4   CoreFoundation                      0x000000010bf78e08 _CF_forwarding_prep_0 + 120
    5   iosAppName                          0x000000010072ada3 +[ThingConfigLoader loadConfig] + 349
    6   iosAppName                          0x000000010073d969 -[ThingSmartSDK startWithAppKey:secretKey:] + 1878
    7   iosAppName                          0x00000001003f2869 $s10iosAppName11AppDelegateC11application_29didFinishLaunchingWithOptionsSbSo13UIApplicationC_SDySo0l6LaunchK3KeyaypGSgtF + 217
    8   iosAppName                          0x00000001003f29e7 $s10iosAppName11AppDelegateC11application_29didFinishLaunchingWithOptionsSbSo13UIApplicationC_SDySo0l6LaunchK3KeyaypGSgtFTo + 183
    9   SwiftUI                             0x00000001160aa7b2 block_destroy_helper.140 + 15626
    10  SwiftUI                             0x00000001160aa88c block_destroy_helper.140 + 15844
    11  UIKitCore                           0x00000001270a42c3 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 271
    12  UIKitCore                           0x00000001270a6186 -[UIApplication _callInitializationDelegatesWithActions:forCanvas:payload:fromOriginatingProcess:] + 4288
    13  UIKitCore                           0x00000001270abed2 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1236
    14  UIKitCore                           0x00000001264c5277 -[_UISceneLifecycleMultiplexer completeApplicationLaunchWithFBSScene:transitionContext:] + 179
    15  UIKitCore                           0x00000001270a83d0 -[UIApplication _compellApplicationLaunchToCompleteUnconditionally] + 59
    16  UIKitCore                           0x00000001270a879b -[UIApplication _run] + 958
    17  UIKitCore                           0x00000001270ad5de UIApplicationMain + 123
    18  SwiftUI                             0x0000000115db55ed __swift_memcpy93_8 + 12403
    19  SwiftUI                             0x0000000115db54a6 __swift_memcpy93_8 + 12076
    20  SwiftUI                             0x00000001154cb610 __swift_memcpy195_8 + 14237
    21  iosAppName                          0x00000001003f25a3 $s10iosAppName0abC3AppV5$mainyyFZ + 35
    22  iosAppName                          0x00000001003f2b19 main + 9
    23  dyld                                0x000000010959c384 start_sim + 10
    24  ???                                 0x00000002011b141f 0x0 + 8608486431
)
libc++abi: terminating due to uncaught exception of type NSException
英文:

I am new on IOS development and I am trying to create lot app using Tuya Smart Life App SDK. I am facing problem when I try to start the app after adding this SDK configure, with appKey and appSecret:

ThingSmartSDK.sharedInstance()?.start(withAppKey: &lt;#your_app_key#&gt;, secretKey: &lt;#your_secret_key#&gt;)

According to the Fast Integration guide this should be placed inside of AppDelegate.m -file, but I have read that this file is not being added to IOS projects automatically any more. (I am using Xcode version '14.3.1')

I have added the AppDelegate class inside of AppNameApp.swift -file and it looks like this:

import SwiftUI
import ThingSmartBaseKit
@main
struct AppNameApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -&gt; Bool {
ThingSmartSDK.sharedInstance().start(withAppKey: &lt;#your_app_key#&gt;, secretKey: &lt;#your_secret_key#&gt;)
#if DEBUG
ThingSmartSDK.sharedInstance().debugMode = true
#else
#endif
return true
}
}

Currently I am not seeing any problem messages coming from this in Xcode, but when I try to run the app on simulator it crashes due to uncaught exception of type NSException. Crash message:

2023-07-13 15:26:50.051841+0300 iosAppName[22835:261964] +[NSArray yy_modelArrayWithClass:json:]: unrecognized selector sent to class 0x10c377890
2023-07-13 15:26:50.086746+0300 iosAppName[22835:261964] *** Terminating app due to uncaught exception &#39;NSInvalidArgumentException&#39;, reason: &#39;+[NSArray yy_modelArrayWithClass:json:]: unrecognized selector sent to class 0x10c377890&#39;
*** First throw call stack:
(
0   CoreFoundation                      0x000000010bf7278b __exceptionPreprocess + 242
1   libobjc.A.dylib                     0x000000010a1e2b73 objc_exception_throw + 48
2   CoreFoundation                      0x000000010bf817dd __CFExceptionProem + 0
3   CoreFoundation                      0x000000010bf76c66 ___forwarding___ + 1443
4   CoreFoundation                      0x000000010bf78e08 _CF_forwarding_prep_0 + 120
5   iosAppName                          0x000000010072ada3 +[ThingConfigLoader loadConfig] + 349
6   iosAppName                          0x000000010073d969 -[ThingSmartSDK startWithAppKey:secretKey:] + 1878
7   iosAppName                          0x00000001003f2869 $s10iosAppName11AppDelegateC11application_29didFinishLaunchingWithOptionsSbSo13UIApplicationC_SDySo0l6LaunchK3KeyaypGSgtF + 217
8   iosAppName                          0x00000001003f29e7 $s10iosAppName11AppDelegateC11application_29didFinishLaunchingWithOptionsSbSo13UIApplicationC_SDySo0l6LaunchK3KeyaypGSgtFTo + 183
9   SwiftUI                             0x00000001160aa7b2 block_destroy_helper.140 + 15626
10  SwiftUI                             0x00000001160aa88c block_destroy_helper.140 + 15844
11  UIKitCore                           0x00000001270a42c3 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 271
12  UIKitCore                           0x00000001270a6186 -[UIApplication _callInitializationDelegatesWithActions:forCanvas:payload:fromOriginatingProcess:] + 4288
13  UIKitCore                           0x00000001270abed2 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1236
14  UIKitCore                           0x00000001264c5277 -[_UISceneLifecycleMultiplexer completeApplicationLaunchWithFBSScene:transitionContext:] + 179
15  UIKitCore                           0x00000001270a83d0 -[UIApplication _compellApplicationLaunchToCompleteUnconditionally] + 59
16  UIKitCore                           0x00000001270a879b -[UIApplication _run] + 958
17  UIKitCore                           0x00000001270ad5de UIApplicationMain + 123
18  SwiftUI                             0x0000000115db55ed __swift_memcpy93_8 + 12403
19  SwiftUI                             0x0000000115db54a6 __swift_memcpy93_8 + 12076
20  SwiftUI                             0x00000001154cb610 __swift_memcpy195_8 + 14237
21  iosAppName                          0x00000001003f25a3 $s10iosAppName0abC3AppV5$mainyyFZ + 35
22  iosAppName                          0x00000001003f2b19 main + 9
23  dyld                                0x000000010959c384 start_sim + 10
24  ???                                 0x00000002011b141f 0x0 + 8608486431
)
libc++abi: terminating due to uncaught exception of type NSException```
</details>
# 答案1
**得分**: 1
经过一段时间的努力,我找到了解决方法。
该应用程序需要作为**Rosetta**模拟器运行,以防止崩溃。
ContentView画布还出现了问题,无法显示预览,但我成功解决了这个问题,**通过关闭“自动刷新画布”**(**编辑器** -> **画布** -> **自动刷新画布**(如果已选中,请取消选中))。
<details>
<summary>英文:</summary>
After fighting for some time over this I found the solution.
The app needs to be run as **Rosetta** simulator to get it to run without crash. 
There was also a problem with ContentView canvas not showing a preview, but I manage to fix this problem **by setting Automatically Refresh Canvas off** (**Editor** -&gt; **Canvas** -&gt; **Automatically Refresh Canvas** (uncheck this if its checked)).
</details>
# 答案2
**得分**: 0
这个错误表明有一些 ObjC 分类没有被加载。请参阅 [Technical Q&amp;A QA1490](https://developer.apple.com/library/archive/qa/qa1490/_index.html) 获取完整的详细信息。您需要在“其他链接器标志”中包含 `-ObjC` 标志。如果您正在使用 CocoaPods,我会期望这已经由 CocoaPods 完成,然而如果您按照 Tuya 的指示操作了,我会建议您与 Tuya 讨论此问题。
<details>
<summary>英文:</summary>
This error indicates that there are ObjC categories that are not being loaded. See [Technical Q&amp;A QA1490](https://developer.apple.com/library/archive/qa/qa1490/_index.html) for full details. You need to include the `-ObjC` flag in Other Linker Flags. I would expect this to have been done by the CocoaPod if you&#39;re using it, however. I would discuss this with Tuya if you&#39;ve followed their instructions.
</details>

huangapple
  • 本文由 发表于 2023年7月13日 21:15:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76679790.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定