PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label iphone. Show all posts
Showing posts with label iphone. Show all posts

Wednesday, November 9, 2022

[FIXED] How to restrict number of characters that can be entered in HTML5 number input field on iPhone

 November 09, 2022     html, input, iphone, jquery-mobile     No comments   

Issue

It seems that neither of the "maxlength", "min" or "max" HTML attributes have the desired effect on iPhone for the following markup:

 <input type="number" maxlength="2" min="0" max="99"/>

Instead of limiting the number of digits or the value of the number entered, the number is just left as it was typed in on iPhone 4. This markup works on most other phones we tested.

What gives?

Any workarounds?

If it is important to the solution, we use jQuery mobile.

Thanks!


Solution

Example

JS

function limit(element)
{
    var max_chars = 2;
         
    if(element.value.length > max_chars) {
        element.value = element.value.substr(0, max_chars);
    }
}

HTML

<input type="number" onkeydown="limit(this);" onkeyup="limit(this);">

If you are using jQuery you can tidy up the JavaScript a little:

JS

var max_chars = 2;
    
$('#input').keydown( function(e){
    if ($(this).val().length >= max_chars) { 
        $(this).val($(this).val().substr(0, max_chars));
    }
});
    
$('#input').keyup( function(e){
    if ($(this).val().length >= max_chars) { 
        $(this).val($(this).val().substr(0, max_chars));
    }
});

HTML

<input type="number" id="input">


Answered By - will
Answer Checked By - Timothy Miller (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Sunday, November 6, 2022

[FIXED] How to access the phone contact list and display it in tableview?

 November 06, 2022     abaddressbook, contacts, iphone, objective-c     No comments   

Issue

Such as the Table cell having:

  1. Contact image

  2. Contact name.

I found that we have to use framework:

  1. AddressBook.framework

  2. AddressBookUI.framework

How can I achieve this?


Solution

ABAddressBookRef addressBook = ABAddressBookCreate(); // create address book reference object
NSArray *abContactArray = (NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook); // get address book contact array

NSInteger totalContacts =[abContactArray count];
    
for(NSUInteger loop= 0 ; loop < totalContacts; loop++)
{
    ABRecordRef record = (ABRecordRef)[abContactArray objectAtIndex:loop]; // get address book record
        
   if(ABRecordGetRecordType(record) ==  kABPersonType) // this check execute if it is person group
    {
            ABRecordID recordId = ABRecordGetRecordID(record); // get record id from address book record
            
            NSString *recordIdString = [NSString stringWithFormat:@"%d",recordId]; // get record id string from record id
            
            NSString *firstNameString = (NSString*)ABRecordCopyValue(record,kABPersonFirstNameProperty); // fetch contact first name from address book  
            NSString *lastNameString = (NSString*)ABRecordCopyValue(record,kABPersonLastNameProperty); // fetch contact last name from address book
    }
}

for more check these links

http://developer.apple.com/library/ios/#documentation/AddressBook/Reference/ABPersonRef_iPhoneOS/Reference/reference.html

http://developer.apple.com/library/ios/#DOCUMENTATION/AddressBook/Reference/ABAddressBookRef_iPhoneOS/Reference/reference.html



Answered By - Sadia
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Friday, October 21, 2022

[FIXED] How to set up a has-many relationship in Cocoa?

 October 21, 2022     has-many, iphone, key-value-coding, objective-c, one-to-many     No comments   

Issue

I'm building a (very) simple FTP app in Cocoa, and I need to store information on the different types of servers that are supported. So, I've created a ServerType class, which stores all of the relevant information about a single type of server. I then have a ServerTypes class which is designed to manage all of the ServerType classes that are created.

My question is, how to set up the relationship between the two objects. Is there a preferred method to do so?

Also, since Objective-C doesn't support non-instance classes, where should I create an instance of ServerTypes that will have to be used throughout the entire program? Or is there a better way to do that? I need it to be KVC compliant so That I can bind one of the ServerType properties to an NSPopupBox.

I'm fairly new to Cocoa and Objective-C.


Solution

To manage a relationship between 2 objects, you have 2 ways: composition or inheritance.

You can inherit from a class to create a subclass then you will have a is-a relationship.

If one object contains another as an instance variable then you will have a has-a relationship.

Here, I think it would be the best to use composition where the ServerTypes objects has an array of all server type objects. Objective-C supports non-instance variable (if that's what you mean), by creating static variable. Then you can use it accross the whole program



Answered By - vodkhang
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Monday, September 26, 2022

[FIXED] How can I evaluate the GPS signal strength? (iPhone)

 September 26, 2022     cllocation, gps, ios, iphone     No comments   

Issue

I need a way of categorising the strength of the GPS signal. So far I have come across the horizontalAccuracy property of CLLocation (Class Reference).

To be more specific I need to create something like the following; the issue I'm having is filling in the if statements.

if (someLocation.horizontalAccuracy ...)
{
    // No Signal
}
else if (someLocation.horizontalAccuracy ...)
{
    // Poor Signal
}
else if (someLocation.horizontalAccuracy ...)
{
    // Average Signal
}
else if (someLocation.horizontalAccuracy ...)
{
    // Good Signal
}
else
{
    // Excellent Signal
}

Please can someone assist me in this?


Solution

I've used figures like this in the past:

if (someLocation.horizontalAccuracy < 0)
{
    // No Signal
}
else if (someLocation.horizontalAccuracy > 163)
{
    // Poor Signal
}
else if (someLocation.horizontalAccuracy > 48)
{
    // Average Signal
}
else
{
    // Full Signal
}

but to be honest, it didn't really work very well for users. It would show as low accuracy, but when they looked at the maps app, it would have located them almost perfectly (albeit with a circle around them).

Rather than trying to define a level of accuracy, and if your app is map based, could you do what Maps does and show the horizontal accuracy as an circular overlay? Then the user can decide for themselves if it's accurate enough.



Answered By - Ashley Mills
Answer Checked By - David Goodson (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Sunday, September 18, 2022

[FIXED] how to print out bool in objective c

 September 18, 2022     boolean, iphone, objective-c, printing     No comments   

Issue

I have set a bool value for key TCshow in my NSUserDefault, I want to run a nslog test whether the key is saved or not, and i m trying to printout the bool value. here is my code but it s not working, any suggestions?

- (IBAction)acceptAction:(id)sender {
//key store to nsuserdefault
self.storedKey = [[NSUserDefaults alloc] init];
[self.storedKey setBool:YES forKey:@"TCshow"];
//trying to print out yes or not, but not working...
NSLog(@"%@", [self.storedKey boolForKey:@"TCshow"]);

}

Solution

%@ is for objects. BOOL is not an object. You should use %d.

It will print out 0 for FALSE/NO and 1 for TRUE/YES.



Answered By - Peter Warbo
Answer Checked By - Marilyn (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Tuesday, July 12, 2022

[FIXED] How to populate OTP from user's message box to application directly in iPhone?

 July 12, 2022     ios, iphone, message, one-time-password, two-factor-authentication     No comments   

Issue

I am working on an internet trading application with its mobile and iPhone applications available. With the recent market trend, we are working on including two-factor authentication. For that, we will be sending a one-time password as a sms on user's registered mobile number.

Is there a way,that the OTP can get automatically populated into application from user's message box in iPhone? What algorithm should I use to make my app read user's message box?

Thanks in advance:)


Solution

You can Access SMS from your app. So better make user to enter his contact number and send SMS to his mobile

-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    if (!url) {
        UIApplication * yourapplication =[UIApplication sharedApplication];
        NSString *outputpath =@"appname://data/";
        NSURL *url =[NSURL URLWithString:outputpath];
        [yourapplication openURL:url];
        return NO;
    }

    NSUserDefaults *defaultString =[NSUserDefaults standardUserDefaults];
    NSString * commonString =[url absoluteString];
    if (commonString.length<=15) {
        //
    }
    else
    {
        [defaultString setObject:commonString forKey:@"urlString"];
    }
         //send info to the screen you need and can navigate
    return YES;
}


Answered By - Charan Giri
Answer Checked By - David Goodson (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to send an email through iOS simulator?

 July 12, 2022     email, iphone, message, sendmessage     No comments   

Issue

I want to know if it's possible to send email through iPhone simulator. I have seen the tutorial for sending an email through iphone as below:

http://www.edumobile.org/iphone/iphone-programming-tutorials/compose-mail-application-in-iphone/

Now to test it is it necessary to have real device? What is the way if I want to send email through iPhone simulator?


Solution

You have to rely on the iOS that the MFMailComposeResult that is handed back in mailComposeController:didFinishWithResult:error: is correct. The simulator fakes that result; no actual mail is sent although it says MFMailComposeResultSent.

The tutorial mentioned misses an important point: The first thing you should do before using MFMailComposeViewController is to check [MFMailComposeViewController canSendMail]. That will return NO, if the user hasn't configured mail on their device. If you must support an iOS version prior to 3.0 the correct way is to check if the class MFMailComposeViewController exists:

Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
if (mailClass != nil)
{
    if ([mailClass canSendMail])
    {
        [self displayComposerSheet];
    }
    else
    {
        [self launchMailAppOnDevice];
    }
}
else
{
    [self launchMailAppOnDevice];
}

The canSendMail-issue can only be tested on a real device though. It will crash if you don't check canSendMail and the user has no mail account configured.



Answered By - Felix
Answer Checked By - Mildred Charles (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Monday, July 11, 2022

[FIXED] How Can We Read Incoming SMS by using Application in iOS

 July 11, 2022     ios, iphone, message, messaging, objective-c     No comments   

Issue

In my application I am able to send an SMS programatically to a particular mobile number when the user clicks submit button. Then there is a response message from that mobile number now I want to read that message and populate that SMS text in to my application.

I searched for this and found that this is not possible in iOS. My question is there any possibility accessing inbox SMS with user permissions?


Solution

Simply two words from Apple:

Not Possible

Detailed:

An iOS app can only access the data for which Apple supplies a documented public API. iOS can not access outside of the sandbox until Apple provides a public API for it. So intercepting/reading an incoming SMS not possible. And no idea when the iOS device is jailbroken.



Answered By - Buntylm
Answer Checked By - Senaida (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Wednesday, June 29, 2022

[FIXED] how to make condition for image and message?

 June 29, 2022     facebook-sdk-4.0, image, ios, iphone, null     No comments   

Issue

in my project i get data from facebookSDK where I need to display images(if available), message(if available), numbers of likes, numbers of comments.

now in my data one image is there but message is not available. my string show me null message. now i need to put 3 conditions.

you can understand my question may be with below code.

        self.arrData = nil;
        self.arrData = [[NSMutableArray alloc]init];
        self.arrData = [result[@"data"] mutableCopy];

        for (int i =0; i<self.arrData.count; i++)
        {

        NSString *strImage1 = [NSString stringWithFormat:@"%@",[[self.arrData objectAtIndex:i]valueForKey:@"full_picture"]];

        NSString *strComment =[NSString stringWithFormat:@"%@", [[self.arrData objectAtIndex:i ]valueForKey:@"message"]];
//in strComment i get @"(null)" message.

        NSString *strLike = [NSString stringWithFormat:@"%@", [[[[self.arrData objectAtIndex:i]valueForKey:@"likes"]valueForKey:@"summary"]valueForKey:@"total_count"]];
        NSString *strCommentCount = [NSString stringWithFormat:@"%@", [[[[self.arrData objectAtIndex:i]valueForKey:@"comments"]valueForKey:@"summary"]valueForKey:@"total_count"]];

        NSString *strTime = [NSString stringWithFormat:@"%@",[[self.arrData objectAtIndex:i]valueForKey:@"created_time"]];


        CustomSocialView *imageView1 = [[CustomSocialView alloc] initWithFrame:CGRectMake(0, 0, width, 170)];

        [self.vLayout addSubview:imageView1];


      //conditions      
            if (strImage1 == nil)// if image is not available.
            {
                NSLog(@"no image");
                [imageView1 setContentText:strComment like:strLike comment:strCommentCount time:strTime];
            }
            else if ([strCommentCount  isEqual: 0]) // if Message is not available // may be here i am wrong.
            {
                NSLog(@"no msg");
                [imageView1 setImage:strImage1 like:strLike comment:strCommentCount time:strTime];
            }
            else 
            {
                NSLog(@"Both image and msg are available");
                [imageView1 setImage:strImage1 setContentText:strComment like:strLike comment:strCommentCount time:strTime];
            }

now i am confused that how can i make condition for my code.

please help me for this.

Thank you.


Solution

Try this:

for (int i = 0; i<self.arrData.count; i++)
    {
       //your code

        if (strImage1 != nil && [strCommentCount intValue] != 0 )// if image is not available.
        {
            NSLog(@"Both image and msg are available");
            [imageView1 setImage:strImage1 setContentText:strComment like:strLike comment:strCommentCount time:strTime];
        }
        else
        {
            if ([strCommentCount intValue] != 0)
            {
                NSLog(@"no image");
                [imageView1 setContentText:strComment like:strLike comment:strCommentCount time:strTime];
            }
            else
            {
                NSLog(@"no msg");
                [imageView1 setImage:strImage1 like:strLike comment:strCommentCount time:strTime];
            }
        }
    }


Answered By - dev_binod
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Thursday, May 19, 2022

[FIXED] How to post (HTTP POST) zipfile and parameters in ObjectiveC?

 May 19, 2022     file-upload, http-post, iphone, web-services, zip     No comments   

Issue

I have tried to Post a Zipfile and some parameters to web service, but i get the response "missing ebook file", so how to Post zip file and parameters in Objectivec please help me

Thanks in Advance

I have tried this:

      NSString *urlString1 = [NSString stringWithFormat:@"http://www.EbookFile.com/index.php?q=api/upload&APPkey=dfsfwerwe324342323432"];



    NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
                [request setURL:[NSURL URLWithString:urlString1]];
                [request setHTTPMethod:@"POST"];

                    NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];
                    NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
                    [request addValue:contentType forHTTPHeaderField: @"Content-Type"];
                    NSMutableData *body = [NSMutableData data];

                // Parameter 1

                [body appendData:[[NSString stringWithFormat:@"--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
                [body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"uid\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
                [body appendData:[uid dataUsingEncoding:NSUTF8StringEncoding]];
                [body appendData:[[NSString stringWithString:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];


                        // Parameter 2

                [body appendData:[[NSString stringWithFormat:@"--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
                [body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"title\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
                [body appendData:[titleText.text dataUsingEncoding:NSUTF8StringEncoding]];
                [body appendData:[[NSString stringWithString:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];

                // Parameter 3


                [body appendData:[[NSString stringWithFormat:@"--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
                [body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"token\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
                [body appendData:[token dataUsingEncoding:NSUTF8StringEncoding]];
                [body appendData:[[NSString stringWithString:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];

                // Parameter 4


                [body appendData:[[NSString stringWithFormat:@"--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
                [body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"desc\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
                [body appendData:[descText.text dataUsingEncoding:NSUTF8StringEncoding]];
                [body appendData:[[NSString stringWithString:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];

                // Parameter 5


                [body appendData:[[NSString stringWithFormat:@"--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
                [body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"cat\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
                [body appendData:[CatId dataUsingEncoding:NSUTF8StringEncoding]];
                [body appendData:[[NSString stringWithString:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];


        // ZIP File Post here

                int r = arc4random() % 8000000;
                NSString *RandomNumber = [NSString stringWithFormat:@"%d",r];
                NSString *file = [RandomNumber stringByAppendingString:@".zip"];

                NSData *Filedata = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath:archivePath]]; // ZIP file convert to NAData here

                [body appendData:[[NSString stringWithFormat:@"Content-Disposition: attachment; name=\"file\"; filename=\"%@\"\r\n",file] dataUsingEncoding:NSUTF8StringEncoding]];
                [body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
                [body appendData:Filedata];
                [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
                [request setHTTPBody:body];

                // pointers to some necessary objects
                NSHTTPURLResponse* response =[[NSHTTPURLResponse alloc] init];
                NSError* error = [[NSError alloc] init] ;

                // synchronous filling of data from HTTP POST response
                NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

                if (error)
                {
                }

 NSString *responseString = [[[NSString alloc] initWithBytes:[responseData bytes]
                                                                     length:[responseData length]
                                                                   encoding:NSUTF8StringEncoding] autorelease];

Solution

 NSString *urlString1 = [NSString stringWithFormat:@"http://www.efferwrwre.com/index.php?q=api/upload&key=f5746442fb9067b3fba83c3da0351f1f"];
    NSLog(@"URLSTribg : %@", urlString1);
    NSString *ww = [urlString1 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
    [request setURL:[NSURL URLWithString:ww]];
    [request setHTTPMethod:@"POST"];
    
    NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];
    NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
    [request addValue:contentType forHTTPHeaderField: @"Content-Type"];
    NSMutableData *body = [NSMutableData data];
        
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"uid\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[uid dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    
    
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"title\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[titleText.text dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    
    
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"token\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[token dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    
    
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"desc\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[descText.text dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];

    
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"cat\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[CatId dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    
    int r = arc4random() % 8000000;
    NSString *RandomNumber = [NSString stringWithFormat:@"%d",r];
    NSString *file = [RandomNumber stringByAppendingString:@".zip"];
    
    NSData *Filedata = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath:archivePath]];
    NSLog(@"file:%@",Filedata);
    
    [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"file\"; filename=\"%@\"\r\n",file] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:Filedata];
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [request setHTTPBody:body];

 NSHTTPURLResponse* response =[[NSHTTPURLResponse alloc] init];
    NSError* error = [[NSError alloc] init] ;
    
    NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    if (error)
    {
        
    }
    
    NSString *responseString = [[[NSString alloc] initWithBytes:[responseData bytes]
                                                         length:[responseData length]
                                                       encoding:NSUTF8StringEncoding] autorelease];
    NSLog(@"%@", responseString);


Answered By - SampathKumar
Answer Checked By - Marilyn (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Monday, May 16, 2022

[FIXED] How to get the display_name from the XML-RPC response in Objective C

 May 16, 2022     ios, iphone, objective-c, wordpress, xml-rpc     No comments   

Issue

In my iPhone app I am accessing a WordPress powered blog using XML-RPC WordPress APIs, and I am fetching the userlists through a XML-RPC method wp.getUsers connection. This is all working fine and I got the response as below (NSLog output):

2012-07-24 11:13:19.317 projectABC[1465:207] (
        {
        "display_name" = "Ravi Interior Design";
        email = "info@xyz.com";
        nicename = abiqsd;
        registered = "2012-05-11 11:58:52 +0000";
        "user_id" = 15;
        username = abssid;
    },
        {
        "display_name" = "qqHeuer";
        email = "aheuer@xyz.com";
        nicename = adamhequer;
        registered = "2012-05-18 15:59:30 +0000";
        "user_id" = 44;
        username = adamhequer;
    },
        {
        "display_name" = "Asdasm Rseyses";
        email = "xyz@abc.net";
        nicename = adaqmraeyes;
        registered = "2012-06-02 18:51:06 +0000";
        "user_id" = 160;
        username = adaqmreyeqs;
    },

Now I need to store only display_name in an NSArray, but I am not getting how to extract only display_name from the above XML-RPC response. How can I achieve this?


Solution

Assuming what you printing is NSArray of Dictionaries,

NSLog(@"%@",[yourArray valueForKeyPath:@"display_name"])


Answered By - Vignesh
Answer Checked By - Marilyn (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Friday, May 6, 2022

[FIXED] How can I get the number of frames per second from a gif file?

 May 06, 2022     animated-gif, frame-rate, image, iphone, objective-c     No comments   

Issue

I am trying to get the number of frames per second from a gif file. I am converting the gif file to NSData and then from that NSData I take an array of frames using this code:

-(NSMutableArray *)getGifFrames:(NSData *)data{
    NSMutableArray *frames = nil;
    CGImageSourceRef src = CGImageSourceCreateWithData((CFDataRef)data, NULL);
    if (src) {
        size_t l = CGImageSourceGetCount(src);
        frames = [NSMutableArray arrayWithCapacity:l];
        for (size_t i = 0; i < l; i++) {
            CGImageRef img = CGImageSourceCreateImageAtIndex(src, i, NULL);
            if (img) {
                [frames addObject:[UIImage imageWithCGImage:img]];
                CGImageRelease(img);
            }   
        }   
        CFRelease(src);
    } 
    return frames;
}

Is there anyway I can get the FPS of the gif?


Solution

A GIF file doesn't contain an FPS value, rather each frame contains a duration.

Each frame contains a header.

Hex Byte Number 324 contains the frame duration in 100ths of a second, for example 09 00 would be 0.09 seconds.

EDIT: reference http://en.wikipedia.org/wiki/Graphics_Interchange_Format#Animated_GIF



Answered By - AnthonyBlake
Answer Checked By - Mildred Charles (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to make one color transparent on a UIImage?

 May 06, 2022     cocoa-touch, core-graphics, image, iphone     No comments   

Issue

On my iPhone app I have a UIImage instance. I want to get a derived a UIImage that is the result of the first UIImage where one of its colors (e.g. magenta) is made transparent. How can I do this?


Solution

-(void)changeColor
{
    UIImage *temp23=[UIImage imageNamed:@"leaf.png"];
    CGImageRef ref1=[self createMask:temp23];
    const float colorMasking[6] = {1.0, 2.0, 1.0, 1.0, 1.0, 1.0};
    CGImageRef New=CGImageCreateWithMaskingColors(ref1, colorMasking);
    UIImage *resultedimage=[UIImage imageWithCGImage:New];
}

-(CGImageRef)createMask:(UIImage*)temp
{
    CGImageRef ref=temp.CGImage;
    int mWidth=CGImageGetWidth(ref);
    int mHeight=CGImageGetHeight(ref);
    int count=mWidth*mHeight*4;
    void *bufferdata=malloc(count);

    CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
    CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
    CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;

    CGContextRef cgctx = CGBitmapContextCreate (bufferdata,mWidth,mHeight, 8,mWidth*4, colorSpaceRef, kCGImageAlphaPremultipliedFirst); 

    CGRect rect = {0,0,mWidth,mHeight};
    CGContextDrawImage(cgctx, rect, ref); 
    bufferdata = CGBitmapContextGetData (cgctx);

    CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, bufferdata, mWidth*mHeight*4, NULL);
    CGImageRef savedimageref = CGImageCreate(mWidth,mHeight, 8, 32, mWidth*4, colorSpaceRef, bitmapInfo,provider , NULL, NO, renderingIntent);
    CFRelease(colorSpaceRef);
    return savedimageref;
}   

The above code is tested and I changed the green color to red color by using mask



Answered By - nasif Noorudeen
Answer Checked By - David Marino (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Monday, February 14, 2022

[FIXED] Accessing Localhost on iPhone using MAMP Pro

 February 14, 2022     apache, iphone, mamp, mysql, php     No comments   

Issue

I have scratched my Head for an hour on this. All Tutorials are outdated, and do not work for me. Even other answers on Stackoverflow are not helpful.

I have an iPhone, iPad, Mac Mini, and a Macbook Pro. All my development is on Macbook pro, using MAMP Pro. I use custom host names.

In system Preferences > Network. My Machines IP Address is 10.0.0.4. So, I am typing 10.0.0.4:80 in iPhone's Safari. I have tried a few different combinations, but none of them seem to work.

But, I am unable to access sites on Macbook's localhost, via my iPhone. This is important for me to speed up development.

Here are the settings in my Mamp.

enter image description here

enter image description here

If anyone could explain What needs to be done. I shall be Greatful.


Solution

That should work. Same setup here and it works.

What do you see on your phone when accessing the IP?

When I check your Screenshots, it seems that MAMP isn't running.
Sure your MAMP is running? :-)
If so, sure your phone is on the same subnet?
Post both IPs. Is there a firewall between?



Answered By - avarx
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Tuesday, December 28, 2021

[FIXED] MAMP - Not working for my iPhone on the same Network

 December 28, 2021     iphone, mamp, php, web-services, webserver     No comments   

Issue

I've been googling this one a lot but I still could not make it work. I have a MAMP web server installed on my mac and I've created some a web service. It work fine when I call it from the browser on my mac when I use localhost:8888/myfile.php and also when I use 192.168.0.108/~martin/myfile.php.

The problem is when I try to call the 192.168.0.108/~martin/myfile.php from my iPhone to do some testing, the requests time out. It is really weird because this was working 2 days ago. I'm not sure what has changed. I'm not very familiar with httpd.conf and htaccess files, but I did not change things there manually.

Any help would be appreciated!


Solution

Have you tried going to http://192.168.0.108:8888/myfile.php on your iPhone? If MAMP is running on 8888 you will need to specify the port to access it there.

Be sure to check your computer's IP too. It's possible that it changed over the last few days depending on your router's setup.

Also, make sure the iPhone is indeed on the same network as your local machine. Depending on your network setup, a subnet might not work either. I've driven myself crazy trying to connect to a box that was actually connected on a separate subnet.



Answered By - saverio
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing