简体   繁体   中英

App Not Sending PNGs

Trying to learn by digging through some code.

Have an accessory button, when its pressed it loads up a menu so the user can pick either a picture from photo library or video (works perfect) have also a sticker menu that pops up similarly to the photo library. The sticker pops up accordingly, only have one if that matters. However when I select it nothing happens. The view is dismissed and it should be sent however it is not.v THE NSLog prints my check statement, I have even added the JSQ sound to play and it does it as well. Working with Firebase/Parse.

It seems to call everything just doesn't attach the PNG from the grid view to the message.

StickerView.m

    - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    [collectionView deselectItemAtIndexPath:indexPath animated:YES];

    NSString *file = stickers2[indexPath.item];
    NSString *sticker = [file stringByReplacingOccurrencesOfString:@"@2x.png" withString:@""];


    if (delegate != nil) [delegate didSelectSticker:sticker];
    NSLog(@"Sticker Sent");
    [self dismissViewControllerAnimated:YES completion:nil];
}

Chat.m

- (void)didSelectSticker:(NSString *)sticker

{
[self messageSend:sticker Video:nil Picture:nil Audio:nil];
}

messageSend

- (void)messageSend:(NSString *)text Video:(NSURL *)video Picture:(UIImage *)picture Audio:(NSString *)audio

{
    Outgoing *outgoing = [[Outgoing alloc] initWith:groupId View:self.navigationController.view];
    [outgoing send:text Video:video Picture:picture Audio:audio Sticker:sticker];
 [JSQSystemSoundPlayer jsq_playMessageSentSound];
    [self finishSendingMessage];
}

LOG

    NSString *file = stickers2[indexPath.item];
NSLog (@"%d",indexPath.item);
NSLog (@"%@",file);
NSString *sticker = [file stringByReplacingOccurrencesOfString:@"@2x.png" withString:@"@2x.png"];
NSLog (@"%@",sticker);
if (delegate != nil) [delegate didSelectSticker:sticker];
NSLog(@"Sticker Sent");
[self dismissViewControllerAnimated:YES completion:nil];

indexPath returns a numerical value based on which sticker is selected. These are loaded into the mutableArray based on file name. If the file name contains a string of @"foo" it is loaded into the array. it could be one or one million value based on how many are loaded in. However it does correspond correctly to the selections. One is properly returned when object one is selected and 2 is properly selected and so on.

File name is returned as the correct file name.

Sticker was returned incorrectly based on your suspicious line of code, I have replaced it to not removed the extensions but did not delete it as of yet. Now returning the same value as File.

Outgoing

- (void)send:(NSString *)text Video:(NSURL *)video Picture:(UIImage *)picture Audio:(NSString *)audio Sticker:(NSString *)sticker

{
    NSMutableDictionary *item = [[NSMutableDictionary alloc] init];
    item[@"userId"] = [PFUser currentId];
    item[@"name"] = [PFUser currentName];
    item[@"date"] = Date2String([NSDate date]);
    item[@"status"] = TEXT_DELIVERED;

    item[@"video"] = item[@"thumbnail"] = item[@"picture"] = item[@"audio"] = item[@"latitude"] = item[@"longitude"] = @"";
    item[@"video_duration"] = item[@"audio_duration"] = @0;
    item[@"picture_width"] = item[@"picture_height"] = @0;

    if (text != nil) [self sendTextMessage:item Text:text];
    else if (video != nil) [self sendVideoMessage:item Video:video];
    else if (picture != nil) [self sendPictureMessage:item Picture:picture];
    else if (audio != nil) [self sendAudioMessage:item Audio:audio];
    else if (sticker !=nil) [self sendSticker:item Sticker:sticker];
    else [self sendLoactionMessage:item];
}

sendSticker

- (void)sendSticker:(NSMutableDictionary *)item Sticker:(NSString *)sticker

{
    item[@"sticker"] = sticker;
    NSLog(@"%@",sticker);
    [self sendMessage:sticker]
}

NSLog never gets called so I know that this is not getting called. I must be missing something, after the user selects the sticker.

Sticker.h

@protocol StickersDelegate

- (void)didSelectSticker:(NSString *)sticker;

@end


@interface StickersView : UIViewController <UICollectionViewDataSource, UICollectionViewDelegate>


@property (nonatomic, assign) IBOutlet id<StickersDelegate>delegate;


@end

I see a couple of potential problem areas, but nothing definitive. I'd check the following either using a debugger or by adding additional logging:

  1. What's the actual numerical value of indexPath.item ? Does it represent a "valid" index into your array stickers2 ?
  2. What is the value of file after you look it up? Is it a valid string, and does it correctly represent the name of an actual file on your file system?
  3. What does the Outgoing class expect for the value of text in its -send:Video:Picture:Audio: method, a fully-qualified path name, or just a simple file name with no path? If the former, you'll either need to look up the system directory and construct the full file path before passing it in, or it would have needed to be constructed that way originally and inserted as such into stickers2 , and if the latter, I'm assuming you will have needed to provided a "base" directory to Firebase/Parse somewhere.
  4. This line is suspicious:

     NSString *sticker = [file stringByReplacingOccurrencesOfString:@"@2x.png" withString:@""]; 

    Do you mean to strip off the extension entirely? In other words, if you have a base filename of "foo@2x.png", then this will change "foo@2x.png" to "foo", is that what you really want. I'm guessing you might want this to be "foo.png" instead:

     NSString *sticker = [file stringByReplacingOccurrencesOfString:@"@2x.png" withString:@".png"]; 

    ?

Hope this helps you track it down.

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