简体   繁体   中英

NSInvalidArgumentException in objective-c call

Sorry, only my second day working with an inherited objective-c project under flutter.

I've just a new method to the obj-c code and its throwing an exception.

I'm guessing there is something wrong with my method signature.

When I inspect the path and callbackUuid variables they have the expected values before the call is made.

The code is being called from flutter/dart but I don't think that has anything to do with the problem.

NSInvalidArgumentException  
unrecognized selector sent to instance xxxx
[NSObject(NSObject) doesNotRecognizeSelector]
_CF_forwarding_prep_0
SoundPlayerManger handlerMethodCall:result

The calling code:

NSString* path = (NSString*)call.arguments[@"path"];
                NSString* callbackUuid = (NSString*)call.arguments[@"callbackUuid"];
                [aSoundPlayer getDuration:path callbackUuid: callbackUuid result:result];

The declaration

- (void)getDuration: (NSString*_Nonnull)path callbackUuid:(NSString*_Nonnull)callbackUuid  result:(FlutterResult _Nonnull )result;

The method I'm calling:


- (void)getDuration: (NSString*)path callbackUuid:(NSString*)callbackUuid  result:(FlutterResult)result
{
        /// let the dart code resume whilst we calculate the duratin.
        result(@"queued");
        NSLog(@"getDuration queued");

        NSURL *afUrl = [NSURL fileURLWithPath:path];
        AudioFileID fileID;
        NSLog(@"Call AudioFileOpenUrl");
        OSStatus status = AudioFileOpenURL((__bridge CFURLRef)afUrl, kAudioFileReadPermission, 0, &fileID);
        Float64 outDataSize = 0;
        UInt32 thePropSize = sizeof(Float64);
        status = AudioFileGetProperty(fileID, kAudioFilePropertyEstimatedDuration, &thePropSize, &outDataSize);
        AudioFileClose(fileID);

        NSLog(@"%@", [NSString stringWithFormat:@"getDuration status%d", (int)status]);

        if (status == kAudioServicesNoError)
        {
                int milliseconds = outDataSize * 1000;

                NSString* args = [NSString stringWithFormat:@"{\"callbackUuid\": \"%@\", \"milliseconds\": %d}"
                                ,callbackUuid
                                , milliseconds ];
                [self invokeCallback:@"durationResults" stringArg:args];
        }
        else
        {
                /// danger will robison, danger
            NSString* args = [NSString stringWithFormat:@"{\"callbackUuid\": \"%@\", \"description\": \"%d\"}"
                              , callbackUuid
                              , (int)status ];
                [self invokeCallback:@"onError" stringArg:args];

        }
        
}

So turns out my method signature was correct it was just that the instance hadn't been created it.

Great message team!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM