chariotsolutions / phonegap-nfc

PhoneGap NFC Plugin
MIT License
712 stars 568 forks source link

IOS : set dialog alertMessage (how i fixed it) #338

Closed simonGleamorb closed 4 years ago

simonGleamorb commented 6 years ago

Hello,

I needed to add alertMessage inside NFC beginSession Dialog. So i add this code to the file NfcPlugin.m

NSString * nfcDescription = [[NSBundle mainBundle] objectForInfoDictionaryKey: @"NFCReaderUsageDescription"];
if ([nfcDescription isEqualToString:@"Read NFC Tags"]) {
      nfcDescription = @" ";
};
_nfcSession.alertMessage = nfcDescription;

So, the begin function looks like this :

- (void)beginSession:(CDVInvokedUrlCommand*)command {
    NSLog(@"beginSession");

    _nfcSession = [[NFCNDEFReaderSession new]initWithDelegate:self queue:nil invalidateAfterFirstRead:TRUE];
    ndefStartSessionCallbackId = [command.callbackId copy];
    NSString * nfcDescription = [[NSBundle mainBundle] objectForInfoDictionaryKey: @"NFCReaderUsageDescription"];
    NSLog(@"%@", nfcDescription);
    if ([nfcDescription isEqualToString:@"Read NFC Tags"]) {
        nfcDescription = @" ";
    };

    _nfcSession.alertMessage = nfcDescription;
    [_nfcSession beginSession];
}

Note : 'Read NFC Tags' string could be anything else. I choose the default description value. Like this, we can choose to display alert message or blank.

Hope it'll help someone.

chaddd980 commented 5 years ago

Sorry, I have no experience with ios development. After i input this code, what exactly do I do to customize the message? I tried doing this;

nfcDescription = @"Please Tap nfc logo ";

I also commented out the if statement. But neither created an alertmessage. Do I need to edit anything in my beginSession function in my ts file?