首页 > 解决方案 > 使用 Ionic 5 在 iOS 上获取 UUID

问题描述

我正在尝试在我的 Ionic 应用程序中获取设备 UUID。为此,我安装了这个:

ionic cordova plugin add cordova-plugin-uniquedeviceid
npm install @ionic-native/unique-device-id

然后我尝试使用以下方法为 ios 构建我的应用程序:

ionic cordova build ios -- --buildFlag="-UseModernBuildSystem=0"

但我总是得到这个错误:

/Users/manuelrodrigues/Desktop/Ionic/gucc/Enfermagem_GUCC/platforms/ios/Enfermagem/Plugins/cordova-plugin-dreamover-uid/OpenUDID.m:191:22: warning: values of type 'NSUInteger' should not be used as format arguments; add an explicit cast to 'unsigned long' instead [-Wformat]
                     (NSUInteger)(arc4random() % NSUIntegerMax)];  
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                     (unsigned long)
/Users/manuelrodrigues/Desktop/Ionic/gucc/Enfermagem_GUCC/platforms/ios/Enfermagem/Plugins/cordova-plugin-dreamover-uid/OpenUDID.m:181:23: warning: implicit conversion loses integer precision: 'unsigned long' to 'CC_LONG' (aka 'unsigned int') [-Wshorten-64-to-32]
        CC_MD5( cStr, strlen(cStr), result );
        ~~~~~~        ^~~~~~~~~~~~
/Users/manuelrodrigues/Desktop/Ionic/gucc/Enfermagem_GUCC/platforms/ios/Enfermagem/Plugins/cordova-plugin-dreamover-uid/OpenUDID.m:233:18: error: cast of C pointer type 'CFStringRef' (aka 'const struct __CFString *') to Objective-C pointer type 'NSString *' requires a bridged cast
        appUID = (NSString *) CFUUIDCreateString(NULL, uuid);
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/manuelrodrigues/Desktop/Ionic/gucc/Enfermagem_GUCC/platforms/ios/Enfermagem/Plugins/cordova-plugin-dreamover-uid/OpenUDID.m:233:31: note: use CFBridgingRelease call to transfer ownership of a +1 'CFStringRef' (aka 'const struct __CFString *') into ARC
        appUID = (NSString *) CFUUIDCreateString(NULL, uuid);
                              ^
                              CFBridgingRelease(            )
/Users/manuelrodrigues/Desktop/Ionic/gucc/Enfermagem_GUCC/platforms/ios/Enfermagem/Plugins/cordova-plugin-dreamover-uid/OpenUDID.m:235:17: error: 'autorelease' is unavailable: not available in automatic reference counting mode
        [appUID autorelease];
                ^
In module 'Foundation' imported from /Users/manuelrodrigues/Desktop/Ionic/gucc/Enfermagem_GUCC/platforms/ios/Enfermagem/Plugins/cordova-plugin-dreamover-uid/OpenUDID.h:47:
In module 'CoreFoundation' imported from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:6:
In module 'Dispatch' imported from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.0.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFStream.h:20:
In module 'os_object' imported from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.0.sdk/usr/include/dispatch/dispatch.h:63:
In module 'ObjectiveC' imported from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.0.sdk/usr/include/os/object.h:111:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.0.sdk/usr/include/objc/NSObject.h:38:1: note: 'autorelease' has been explicitly marked unavailable here
- (instancetype)autorelease OBJC_ARC_UNAVAILABLE;
^
/Users/manuelrodrigues/Desktop/Ionic/gucc/Enfermagem_GUCC/platforms/ios/Enfermagem/Plugins/cordova-plugin-dreamover-uid/OpenUDID.m:235:17: error: ARC forbids explicit message send of 'autorelease'
        [appUID autorelease];
         ~~~~~~ ^
/Users/manuelrodrigues/Desktop/Ionic/gucc/Enfermagem_GUCC/platforms/ios/Enfermagem/Plugins/cordova-plugin-dreamover-uid/OpenUDID.m:344:17: warning: 'setPersistent:' is deprecated: first deprecated in iOS 10.0 - Do not set persistence on pasteboards. This property is set automatically.
      [-Wdeprecated-declarations]
        [slotPB setPersistent:YES];
                ^
In module 'UIKit' imported from /Users/manuelrodrigues/Desktop/Ionic/gucc/Enfermagem_GUCC/platforms/ios/Enfermagem/Plugins/cordova-plugin-dreamover-uid/OpenUDID.m:50:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.0.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIPasteboard.h:44:1: note: 'setPersistent:' has been explicitly marked deprecated here
- (void)setPersistent:(BOOL)persistent API_DEPRECATED("Do not set persistence on pasteboards. This property is set automatically.", ios(3.0, 10.0));
^
/Users/manuelrodrigues/Desktop/Ionic/gucc/Enfermagem_GUCC/platforms/ios/Enfermagem/Plugins/cordova-plugin-dreamover-uid/OpenUDID.m:377:73: error: 'retain' is unavailable: not available in automatic reference counting mode
        kOpenUDIDSessionCache = [[NSString stringWithFormat:@"%040x",0] retain];
                                                                        ^
In module 'Foundation' imported from /Users/manuelrodrigues/Desktop/Ionic/gucc/Enfermagem_GUCC/platforms/ios/Enfermagem/Plugins/cordova-plugin-dreamover-uid/OpenUDID.h:47:
In module 'CoreFoundation' imported from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:6:
In module 'Dispatch' imported from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.0.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFStream.h:20:
In module 'os_object' imported from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.0.sdk/usr/include/dispatch/dispatch.h:63:
In module 'ObjectiveC' imported from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.0.sdk/usr/include/os/object.h:111:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.0.sdk/usr/include/objc/NSObject.h:36:1: note: 'retain' has been explicitly marked unavailable here
- (instancetype)retain OBJC_ARC_UNAVAILABLE;
^
/Users/manuelrodrigues/Desktop/Ionic/gucc/Enfermagem_GUCC/platforms/ios/Enfermagem/Plugins/cordova-plugin-dreamover-uid/OpenUDID.m:377:73: error: ARC forbids explicit message send of 'retain'
        kOpenUDIDSessionCache = [[NSString stringWithFormat:@"%040x",0] retain];
                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
/Users/manuelrodrigues/Desktop/Ionic/gucc/Enfermagem_GUCC/platforms/ios/Enfermagem/Plugins/cordova-plugin-dreamover-uid/OpenUDID.m:393:39: error: 'retain' is unavailable: not available in automatic reference counting mode
    kOpenUDIDSessionCache = [openUDID retain];
                                      ^
In module 'Foundation' imported from /Users/manuelrodrigues/Desktop/Ionic/gucc/Enfermagem_GUCC/platforms/ios/Enfermagem/Plugins/cordova-plugin-dreamover-uid/OpenUDID.h:47:
In module 'CoreFoundation' imported from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:6:
In module 'Dispatch' imported from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.0.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFStream.h:20:
In module 'os_object' imported from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.0.sdk/usr/include/dispatch/dispatch.h:63:
In module 'ObjectiveC' imported from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.0.sdk/usr/include/os/object.h:111:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.0.sdk/usr/include/objc/NSObject.h:36:1: note: 'retain' has been explicitly marked unavailable here
- (instancetype)retain OBJC_ARC_UNAVAILABLE;
^
/Users/manuelrodrigues/Desktop/Ionic/gucc/Enfermagem_GUCC/platforms/ios/Enfermagem/Plugins/cordova-plugin-dreamover-uid/OpenUDID.m:393:39: error: ARC forbids explicit message send of 'retain'
    kOpenUDIDSessionCache = [openUDID retain];
                             ~~~~~~~~ ^
3 warnings and 8 errors generated.

CompileC /var/root/Library/Developer/Xcode/DerivedData/Enfermagem-gcyrejjiyzjsnjfismvshrejfpfi/Build/Intermediates.noindex/Enfermagem.build/Debug-iphonesimulator/Enfermagem.build/Objects-normal/x86_64/CDVFile.o Enfermagem/Plugins/cordova-plugin-file/CDVFile.m normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.compiler
    cd /Users/manuelrodrigues/Desktop/Ionic/gucc/Enfermagem_GUCC/platforms/ios
    export LANG=en_US.US-ASCII
    export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/Users/manuelrodrigues/Desktop/Ionic/gucc/Enfermagem_GUCC/node_modules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Users/manuelrodrigues/.gradle/wrapper/dists/gradle-6.5.1-all/cdund22i8guosqylfo49op4dv/gradle-6.5.1/bin/"
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c -target x86_64-apple-ios11.0-simulator -fmessage-length=308 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -fcolor-diagnostics -std=c99 -fobjc-arc -fmodules -gmodules -fmodules-cache-path=/var/root/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -fmodules-prune-interval=86400 -fmodules-prune-after=345600 -fbuild-session-file=/var/root/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/Session.modulevalidation -fmodules-validate-once-per-build-session -Wno-trigraphs -fpascal-strings -O0 -fno-common -Wno-missing-field-initializers -Wno-missing-prototypes -Wunreachable-code -Wno-implicit-atomic-properties -Wno-objc-interface-ivars -Wno-arc-repeated-use-of-weak -Wimplicit-retain-self -Wduplicate-method-match -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wuninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wno-float-conversion -Wnon-literal-null-conversion -Wobjc-literal-conversion -Wshorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wundeclared-selector -Wdeprecated-implementations -DWK_WEB_VIEW_ONLY=0 -DDEBUG=1 -DOBJC_OLD_DISPATCH_PROTOTYPES=0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.0.sdk -fasm-blocks -fstrict-aliasing -Wprotocol -Wdeprecated-declarations -g -Wno-sign-conversion -Winfinite-recursion -Wcomma -Wblock-capture-autoreleasing -Wstrict-prototypes -Wno-semicolon-before-method-body -fobjc-abi-version=2 -fobjc-legacy-dispatch -index-store-path /var/root/Library/Developer/Xcode/DerivedData/Enfermagem-gcyrejjiyzjsnjfismvshrejfpfi/Index/DataStore -iquote /var/root/Library/Developer/Xcode/DerivedData/Enfermagem-gcyrejjiyzjsnjfismvshrejfpfi/Build/Intermediates.noindex/Enfermagem.build/Debug-iphonesimulator/Enfermagem.build/Enfermagem-generated-files.hmap -I/var/root/Library/Developer/Xcode/DerivedData/Enfermagem-gcyrejjiyzjsnjfismvshrejfpfi/Build/Intermediates.noindex/Enfermagem.build/Debug-iphonesimulator/Enfermagem.build/Enfermagem-own-target-headers.hmap -I/var/root/Library/Developer/Xcode/DerivedData/Enfermagem-gcyrejjiyzjsnjfismvshrejfpfi/Build/Intermediates.noindex/Enfermagem.build/Debug-iphonesimulator/Enfermagem.build/Enfermagem-all-target-headers.hmap -iquote /var/root/Library/Developer/Xcode/DerivedData/Enfermagem-gcyrejjiyzjsnjfismvshrejfpfi/Build/Intermediates.noindex/Enfermagem.build/Debug-iphonesimulator/Enfermagem.build/Enfermagem-project-headers.hmap -I/Users/manuelrodrigues/Desktop/Ionic/gucc/Enfermagem_GUCC/platforms/ios/build/emulator/include -I/Users/manuelrodrigues/Desktop/Ionic/gucc/Enfermagem_GUCC/platforms/ios/build/emulator/usr/local/lib/include -I/var/root/Library/Developer/Xcode/DerivedData/Enfermagem-gcyrejjiyzjsnjfismvshrejfpfi/Build/Intermediates.noindex/UninstalledProducts/include -I/var/root/Library/Developer/Xcode/DerivedData/Enfermagem-gcyrejjiyzjsnjfismvshrejfpfi/Build/Intermediates.noindex/UninstalledProducts/iphonesimulator/include -I/Users/manuelrodrigues/Desktop/Ionic/gucc/Enfermagem_GUCC/platforms/ios/build/emulator -I/var/root/Library/Developer/Xcode/DerivedData/Enfermagem-gcyrejjiyzjsnjfismvshrejfpfi/Build/Intermediates.noindex/Enfermagem.build/Debug-iphonesimulator/Enfermagem.build/DerivedSources-normal/x86_64 -I/var/root/Library/Developer/Xcode/DerivedData/Enfermagem-gcyrejjiyzjsnjfismvshrejfpfi/Build/Intermediates.noindex/Enfermagem.build/Debug-iphonesimulator/Enfermagem.build/DerivedSources/x86_64 -I/var/root/Library/Developer/Xcode/DerivedData/Enfermagem-gcyrejjiyzjsnjfismvshrejfpfi/Build/Intermediates.noindex/Enfermagem.build/Debug-iphonesimulator/Enfermagem.build/DerivedSources -F/Users/manuelrodrigues/Desktop/Ionic/gucc/Enfermagem_GUCC/platforms/ios/build/emulator -include /Users/manuelrodrigues/Desktop/Ionic/gucc/Enfermagem_GUCC/platforms/ios/build/sharedpch/Enfermagem-Prefix-fwllpxsetbylsmedazmsnzuxdpzc/Enfermagem-Prefix.pch -MMD -MT dependencies -MF /var/root/Library/Developer/Xcode/DerivedData/Enfermagem-gcyrejjiyzjsnjfismvshrejfpfi/Build/Intermediates.noindex/Enfermagem.build/Debug-iphonesimulator/Enfermagem.build/Objects-normal/x86_64/CDVFile.d --serialize-diagnostics /var/root/Library/Developer/Xcode/DerivedData/Enfermagem-gcyrejjiyzjsnjfismvshrejfpfi/Build/Intermediates.noindex/Enfermagem.build/Debug-iphonesimulator/Enfermagem.build/Objects-normal/x86_64/CDVFile.dia -c /Users/manuelrodrigues/Desktop/Ionic/gucc/Enfermagem_GUCC/platforms/ios/Enfermagem/Plugins/cordova-plugin-file/CDVFile.m -o /var/root/Library/Developer/Xcode/DerivedData/Enfermagem-gcyrejjiyzjsnjfismvshrejfpfi/Build/Intermediates.noindex/Enfermagem.build/Debug-iphonesimulator/Enfermagem.build/Objects-normal/x86_64/CDVFile.o

** BUILD FAILED **


The following build commands failed:
        CompileC /var/root/Library/Developer/Xcode/DerivedData/Enfermagem-gcyrejjiyzjsnjfismvshrejfpfi/Build/Intermediates.noindex/Enfermagem.build/Debug-iphonesimulator/Enfermagem.build/Objects-normal/x86_64/OpenUDID.o Enfermagem/Plugins/cordova-plugin-dreamover-uid/OpenUDID.m normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)
xcodebuild: Command failed with exit code 65
[ERROR] An error occurred while running subprocess cordova.
        
        cordova build ios --buildFlag=-UseModernBuildSystem=0 exited with exit code 65.
        
        Re-running this command with the --verbose flag may provide more information.

我怎么解决这个问题?在android上它工作正常。

这是示例代码的链接: https ://ionicframework.com/docs/native/unique-device-id

标签: iosionic-frameworkbuildionic4

解决方案


推荐阅读