Wednesday, 7 February 2018

Find the index of object in array in swift 4



userList is array of objects [User]
userID is identity of object, which is use for find index. 



let userID = "1"

 let tempIndex = userList.index(where: { (user: User) -> Bool in
            user.userID == userID

        })


tempIndex is position of object in userList array. 

You may access the object like bellow
let objUser = userList[tempIndex]



Happy coding! 



Bhavesh Kumbhani
IOS Software Professional 

follow on

Filter array of objects in swift 4


userList is array of objects [User]
userID is identity of object, which is use for filter 

See bellow method, In this method filtered the userList array by userID. get all users which are having same userID.



func filtered(userID: String) -> [User] {
        if userList.count > 0{
            let filteredArray = userList.filter { (obj) -> Bool in
                obj.userID == userID
            }
            return filteredArray
        }
        return []
    }
 







Happy coding! 



Bhavesh Kumbhani
IOS Software Professional 

follow on

Unbalanced calls to begin/end appearance transitions for...

This type of error logs print when your presented view-controller is diapering while you trying to present another controller like..
  • UIAlertView
  • UIAlertController
  • Present Model View Controller...etc.


Solution is within a second.

Keep remember above all type of controller present after the disappear presented controller successful. 

  1. Set disappear delegate, in this callback you may present above types of controllers 
  2. Add 0.5 second timer to present above types of controllers 



Happy coding! 



Bhavesh Kumbhani
IOS Software Professional 

follow on
Facebook
LinkedIn


Wednesday, 20 January 2016

This build is invalid on itunesconnect

Please follow bellow steps to encounter the issue.


  • Upgrade latest OS X
  • Use latest XCODE version 
  • Verify app icons in bundle or  in Assets.xcassets. (mostly issue due to dose not added proper size of  icons, even you missed any single icon then also getting this type error)
  • Verify provisioning profile 
  • Use Latest Application Loader for submit package (ipa)



Happy coding! 



Bhavesh Kumbhani
IOS Software Professional 

follow on
Facebook
LinkedIn


Wednesday, 13 January 2016

Apple Push Notification PHP script

<?php
    
    // set time limit to zero in order to avoid timeout
    set_time_limit(0);
    
    // charset header for output
    header('content-type: text/html; charset: utf-8');
    
    // this is the pass phrase you defined when creating the key
    $passphrase = 'test';
    
    // you can post a variable to this string or edit the message here
    if (!isset($_POST['msg'])) {
        $_POST['msg'] = "Test msg!";
    }
    
    // tr_to_utf function needed to fix the Turkish characters
    $message = tr_to_utf($_POST['msg']);
    
    // load your device ids to an array
    $deviceIds = array(
                       'devicetoken1',
                       'devicetoken2'
                       );
    
    // this is where you can customize your notification
    $payload = '{"aps":{"alert":"' . $message . '","sound":"default"}}';
    
    $result = 'Start' . '<br />';
    
    ////////////////////////////////////////////////////////////////////////////////
    // start to create connection
    $ctx = stream_context_create();
    stream_context_set_option($ctx, 'ssl', 'local_cert', 'apns.pem');
    stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
    
    echo count($deviceIds) . ' devices will receive notifications.<br />';
    
    foreach ($deviceIds as $item) {
        // wait for some time
        sleep(1);
        
        // Open a connection to the APNS server
        $fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx);
        
        if (!$fp) {
            exit("Failed to connect: $err $errstr" . '<br />');
        } else {
            echo 'Apple service is online. ' . '<br />';
        }
        
        // Build the binary notification
        $msg = chr(0) . pack('n', 32) . pack('H*', $item) . pack('n', strlen($payload)) . $payload;
        
        // Send it to the server
        $result = fwrite($fp, $msg, strlen($msg));
        
        if (!$result) {
            echo 'Undelivered message count: ' . $item . '<br />';
        } else {
            echo 'Delivered message count: ' . $item . '<br />';
        }
        
        if ($fp) {
            fclose($fp);
            echo 'The connection has been closed by the client' . '<br />';
        }
    }
    
    echo count($deviceIds) . ' devices have received notifications.<br />';
    
    // function for fixing Turkish characters
    function tr_to_utf($text) {
        $text = trim($text);
        $search = array('Ü', 'Þ', 'Ð', 'Ç', 'Ý', 'Ö', 'ü', 'þ', 'ð', 'ç', 'ý', 'ö');
        $replace = array('Ü', 'Åž', '&#286;ž', 'Ç', 'İ', 'Ö', 'ü', 'ÅŸ', 'ÄŸ', 'ç', 'ı', 'ö');
        $new_text = str_replace($search, $replace, $text);
        return $new_text;
    }
    
    // set time limit back to a normal value
    set_time_limit(30);

    ?>

Saturday, 20 June 2015

Quick fix - duplicate symbols for architecture x86_64 issue

Go through bellow steps and resolve the issue.


1. Please check your source bundled - Does have any files added two time?  If yes, then delete one of any one copy, and chose option remove from reference.

For example test.h or test.m  file have in your bundled but by mistake test.h or test.m files again added in some other directory, now your bundled having a two clone copy of same files.

2. Be careful check your code structure, have there any global class declaration & create instance of it, just remove instance from there and keep in app delegate for global access or create instance in  class file where you want that class.


For example your bundled have global.h  file this file having list of declaration header files for global access, if also you have created instance there so remove it from there.

Code look like in your global.h file.

#import "test.h"

test *objTest;


Above code having issue some time, get duplicate symbol error while compile source. Just declaration is ok but can't create  instance in global.h file, instance create in app delegate or in class file where you want.

Optimised above cases in XCODE 6.3.2, OS X 10.10.3





Bhavesh Kumbhani
IOS Software Professional 

follow on
Facebook
LinkedIn


Wednesday, 25 March 2015

Could not inspect application package.

If you encounter the following error:
 "Could not inspect application package."

Follow below steps without wasting time on finding any other solution:
1. Remove .plist file from source after the take backup of .plist file
2. Add New .plist..like (AppName.plist)
3. Open old .plist file (backup file )
4. Just copy paste all the data from old .plist to new .plist file (copy row one by one)
5.Create build and share your app over the air.

Thanks in advance,

Bhavesh Kumbhani
IOS Software Professional 

follow on
Facebook
LinkedIn