Click here to Skip to main content
15,867,999 members
Home / Discussions / Objective-C and Swift
   

Objective-C and Swift

 
AnswerRe: Can i use scanline Flood Fill algorithm to apply gradient in UIImage?How to use? Pin
Richard MacCutchan11-May-17 21:15
mveRichard MacCutchan11-May-17 21:15 
QuestionCrashing in printing Pin
Le@rner5-Apr-17 1:22
Le@rner5-Apr-17 1:22 
AnswerRe: Crashing in printing Pin
Surya_Narayan10-Apr-17 23:26
professionalSurya_Narayan10-Apr-17 23:26 
GeneralRe: Crashing in printing Pin
Le@rner11-Apr-17 22:19
Le@rner11-Apr-17 22:19 
QuestionHow to get the sensor data Pin
Member 1302743027-Feb-17 14:56
Member 1302743027-Feb-17 14:56 
AnswerRe: How to get the sensor data Pin
Richard MacCutchan27-Feb-17 21:22
mveRichard MacCutchan27-Feb-17 21:22 
Questionimage from custom NSView , image quality is very bad. Pin
Le@rner16-Jan-17 18:50
Le@rner16-Jan-17 18:50 
AnswerRe: image from custom NSView , image quality is very bad. Pin
Surya_Narayan10-Apr-17 23:31
professionalSurya_Narayan10-Apr-17 23:31 
GeneralRe: image from custom NSView , image quality is very bad. Pin
Le@rner11-Apr-17 22:17
Le@rner11-Apr-17 22:17 
QuestionSimultaneous Microphone Access on iPhone Pin
Member 123773388-Mar-16 0:35
Member 123773388-Mar-16 0:35 
QuestionObjective C first program from the book, warning messages Pin
Alla__10-Nov-15 1:44
Alla__10-Nov-15 1:44 
AnswerRe: Objective C first program from the book, warning messages Pin
BharathReddy V12-Jan-16 2:04
BharathReddy V12-Jan-16 2:04 
QuestionLinker command failed with exit code 1 (use -v to see invocation) in xcode 5.1.1 Pin
Member 1198376314-Sep-15 10:17
Member 1198376314-Sep-15 10:17 
QuestionImagePickerController image size Pin
liel333-Aug-15 11:30
liel333-Aug-15 11:30 
AnswerRe: ImagePickerController image size Pin
biji cabe18-Dec-16 22:25
biji cabe18-Dec-16 22:25 
QuestioniOS XMPP received message in coversation screen Pin
Member 1176696715-Jun-15 2:37
Member 1176696715-Jun-15 2:37 
I am working on XMPP based project. i am able to send message and it displays in conversation screen but when i receive message it only show in alertview not able to see in conversation screen. help me please.


Objective-C
 - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(messageReceived:) name:MessageRecivedNotif object:nil];

appdelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
[self getAllMessagesArrayWithOppositeUser:_jid];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(keyboardWasShown:)
                                             name:UIKeyboardDidShowNotification
                                           object:nil];


}

#pragma mark table delegate and datasource methods
 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return data.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tblobj dequeueReusableCellWithIdentifier:@"cell"];
UILabel *lbl;
if (cell==nil)
{
    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];

    if (chatLblRight == 1)
    {
        lbl = [[UILabel alloc]initWithFrame:CGRectMake(200, 10, 150, 44)];
        [lbl setTextColor:[UIColor redColor]];
        [cell.contentView   addSubview:lbl];
    }


 }
 if (chatLblRight == 1)
 {
    lbl.text = [[data objectAtIndex:indexPath.row]valueForKey:@"text"];
    chatLblRight = 0;
    lbl = [[UILabel alloc]initWithFrame:CGRectMake(200, 10, 150, 44)];
    [lbl setTextColor:[UIColor redColor]];
    [cell.contentView   addSubview:lbl];

    return cell;
  }
  else
  {
    cell.textLabel.text=[[data objectAtIndex:indexPath.row]valueForKey:@"text"];
    return cell;
  }
}
-(void)messageReceived:(NSNotification*)notif
{
XMPPMessage *message=(XMPPMessage*)notif.object;
NSString *body = [[message elementForName:@"body"] stringValue];
NSMutableDictionary *dic_recive = [[NSMutableDictionary alloc]init];
[dic_recive setObject:body forKey:@"text"];
[data addObject:dic_recive];
chatLblRight = 1;
[tblobj reloadData];
}
 -(IBAction)btnsend:(id)sender
{
[txtmsg resignFirstResponder];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.2];
[msgview setFrame:CGRectMake(0, self.view.bounds.size.height-53, self.view.bounds.size.width, 53)];
[UIView commitAnimations];
[((AppDelegate*)[[UIApplication sharedApplication]delegate]) sendMessage:txtmsg.text toUserWithJid:_jid];
NSMutableDictionary *dic_send = [[NSMutableDictionary alloc]init];
[dic_send setObject:txtmsg.text forKey:@"text"];
[data addObject:dic_send];
[tblobj reloadData];
txtmsg.text=@"";
 }
-(NSMutableArray *)getAllMessagesArrayWithOppositeUser:(XMPPJID *)xmppUser
{
XMPPMessageArchivingCoreDataStorage *storage = [XMPPMessageArchivingCoreDataStorage sharedInstance];
NSManagedObjectContext *moc = [storage mainThreadManagedObjectContext];
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"XMPPMessageArchiving_Message_CoreDataObject"
                                                     inManagedObjectContext:moc];
NSFetchRequest *request = [[NSFetchRequest alloc]init];
[request setEntity:entityDescription];
NSError *error;
NSArray *messages = [moc executeFetchRequest:request error:&error];

data=[[NSMutableArray alloc] init];

@autoreleasepool {
    for (XMPPMessageArchiving_Message_CoreDataObject *message in messages) {

        if ([message.bareJid isEqual:xmppUser])
        {
            NSMutableDictionary *dict=[[NSMutableDictionary alloc] init];
            [dict setObject:message.body forKey:@"text"];
            [dict setObject:message.timestamp forKey:@"date"];
            if ([message isOutgoing]) {
                [dict setObject:@"1" forKey:@"type"];
                [dict setObject:[[message.bareJidStr componentsSeparatedByString:@"@"] firstObject] forKey:@"username"];
                [dict setObject:[UIColor greenColor] forKey:@"color"];
            }
            else{

                [dict setObject:@"2" forKey:@"type"];
                [dict setObject:[[message.bareJidStr componentsSeparatedByString:@"@"] firstObject] forKey:@"username"];
                //                    [dict setObject:userName forKey:@"username"];
                [dict setObject:[UIColor blueColor] forKey:@"color"];
             }
            [data addObject:dict];
          }
      }
  }

   return data;
}

Where is my mistake ?

EDIT:-
Objective-C
- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message
{
    
    DDLogVerbose(@"%@: %@", THIS_FILE, THIS_METHOD);
[[self xmppStream] sendElement:message];
    
    UILocalNotification *localNotification = [[UILocalNotification alloc] init];
    localNotification.alertAction = @"OK";
    localNotification.fireDate = [NSDate date];
    //localNotification.alertBody = xmppmessage;
    localNotification.soundName = UILocalNotificationDefaultSoundName;
    [[UIApplication sharedApplication] presentLocalNotificationNow:localNotification];

    
    
    
    // A simple example of inbound message handling.
    
   if ([message isChatMessageWithBody])
    {
        XMPPUserCoreDataStorageObject *user = [xmppRosterStorage userForJID:[message from]
                                                                 xmppStream:xmppStream
                                                       managedObjectContext:[self managedObjectContext_roster]];
        
        NSString *body = [[message elementForName:@"body"] stringValue];
        NSString *displayName = [user displayName];
        
        if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateActive)
        {
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:displayName
                                                                message:body
                                                               delegate:nil
                                                      cancelButtonTitle:@"Ok"
                                                      otherButtonTitles:nil];
            [alertView show];
        }
        else
        {
            // We are not active, so use a local notification instead
            UILocalNotification *localNotification = [[UILocalNotification alloc] init];
            localNotification.alertAction = @"Ok";
            localNotification.alertBody = [NSString stringWithFormat:@"From: %@\n\n%@",displayName,body];
            
            [[UIApplication sharedApplication] presentLocalNotificationNow:localNotification];
        }
    }


modified 16-Jun-15 2:45am.

SuggestionRe: iOS XMPP received message in coversation screen Pin
Richard MacCutchan15-Jun-15 4:19
mveRichard MacCutchan15-Jun-15 4:19 
GeneralRe: iOS XMPP received message in coversation screen Pin
Member 1176696715-Jun-15 20:42
Member 1176696715-Jun-15 20:42 
AnswerRe: iOS XMPP received message in coversation screen Pin
Dennis E White17-Jun-15 5:54
professionalDennis E White17-Jun-15 5:54 
Questionmake a system monitor using obj c. Pin
Member 116779679-May-15 13:00
Member 116779679-May-15 13:00 
AnswerRe: make a system monitor using obj c. Pin
Richard MacCutchan9-May-15 21:10
mveRichard MacCutchan9-May-15 21:10 
GeneralRe: make a system monitor using obj c. Pin
Dennis E White15-May-15 5:25
professionalDennis E White15-May-15 5:25 
GeneralRe: make a system monitor using obj c. Pin
Richard MacCutchan15-May-15 5:41
mveRichard MacCutchan15-May-15 5:41 
GeneralRe: make a system monitor using obj c. Pin
Dennis E White15-May-15 6:04
professionalDennis E White15-May-15 6:04 
GeneralApp that converts human years to dog years Pin
Member 115920608-Apr-15 15:44
Member 115920608-Apr-15 15:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.