Showing posts with label iphoneSDK. Show all posts
Showing posts with label iphoneSDK. Show all posts

Wednesday, July 30, 2014

iOS define local and global NSString constant

situee.blogspot.com

1. Local Constant

There are two type of constants.

(1)  static NSString * const kMyConstant = @"constant string";

(2)  #define kMyConstant @"constant string"


"static const" is a better way, although "#define" is much shorter,

Here are some reasons:

  • "#define" are not type-safe. 
  • We can test the value of the "static const" constant with debugger;
  • Memory. Preprocessor create a new string each time the macro appear, while "static const" reuse the same string.

2. Global Constant

----------------  .h file  --------------

extern NSString *const kMyConstant;

----------------  .m file  --------------
// define in a .m file OUTSIDE @implementation like...

NSString *const kMyConstant = @"my constant";

The extern declaration says that there exists an NSString * const by the name kMyConstant whose storage is created in some other place.[1]

Remove the static -- that specifies that kMyConstant is only visible in files linked with this one.[1]

Monday, August 05, 2013

iOS handle Remote Push Notification

There are three cases to handle remote push notification.
  1. Your app was just launched
    handle callback didFinishLaunchingWithOptions application launched by clicking "View" when app is not running
  2. Your app was just brought from background to foreground
    by clicking "View" when app is running in background.
    handle callback didReceiveRemoteNotification
  3. Your app was already running in the foreground
    handle callback didReceiveRemoteNotification
Both (2) and (3) are handled by didReceiveRemoteNotification, use the following code to distinguish forground and background.

Thursday, April 25, 2013

sudzC SOAP web service namespace problem



I am using sudzC to generate objective-C codes to use SOAP webservice of a Java Tomcat server.
But is doesn't work. There must be some formatting problem.


<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://example.com/"><soap:Body>
<getMethod>
    <arg0>aaa</arg0>
    <arg1>8</arg1>
</getMethod>
</soap:Body></soap:Envelope>


return error message:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body>
<soap:Fault><faultcode>soap:Client</faultcode>
<faultstring>Unmarshalling Error: unexpected element (uri:"http://example.com/", local:"arg0"). Expected elements are &lt;{}arg0&gt;,&lt;{}arg1&gt; </faultstring></soap:Fault>
</soap:Body></soap:Envelope>

server is expecting <{}arg0>, <{}arg1>
{} means the namespace is empty.
arg0 and arg1 should have NO namespace.

Friday, March 29, 2013

Apple iOS UDID Replacement - UUID,vendor,advertising id

Apple forbid all new / updated app of iphone to use UDID from May 1st, 2013.
There are some replacements : CFUUID/NSUUID, Vendor ID or Advertising ID.


 
Scope
Lifetime end
Available
UUID
Application
Uninstall app
iOS 2
Vendor ID
Development Team
Uninstall all apps of the development team
iOS 6
Advertising ID
Device
Wipe device
iOS 6



Tuesday, September 04, 2012

iOS Objective-C performSelector static method


It's tested OK to use the following static method calls.
Tested on Xcode Version 4.4.1 (4F1003), Apple LLVM Compiler 4.0
    [[StaticMethodClass classperformSelectorInBackground:@selector(runInThreadMethod)withObject:nil];
    [StaticMethodClass performSelectorInBackground:@selector(runInThreadMethod)withObject:nil];
    [StaticMethodClass performSelectorOnMainThread:@selector(runInThreadMethod)withObject:nil waitUntilDone:NO];
    [StaticMethodClass performSelector:@selector(runInThreadMethod) withObject:nil];
Although, there is no auto-code-completion, but it runs fine.
But when use "target", it's NOT ok to use the Class itself, should use "[StaticMethodClass class]" as the target. like.
 [NSTimer scheduledTimerWithTimeInterval:1.0 target:[StaticMethodClass classselector:@selector(runInThreadMethod) userInfo:nil repeats:NO];

Monday, September 03, 2012

iOS Objective-C schedule NSTimer with static method target

Usually we schedule NSTimer like:


    [NSTimer scheduledTimerWithTimeInterval:2.0
             target:instance
             selector:@selector(targetMethod)
             userInfo:nil
             repeats:YES];

targetMethod is an instance method of the instance.

What if we want to schedule to run a static method (or class method) of a class?
Just replace the "instance" with "[ClassA class]".


    [NSTimer scheduledTimerWithTimeInterval:2.0
             target:[ClassA class]
             selector:@selector(staticMethod)
             userInfo:nil
             repeats: YES];

"staticMethod" is a static method of ClassA.
"[ClassA class]" is the target object.


Friday, September 09, 2011

Enable/Renew Team Provisioning Profile:*

There is a Team Provisioning Profile:* in Current Provisioning Profiles in iDP portal.
It's a Wildcard AppID. You don't need to create a AppID and download specified provisioning profile for that AppID. You can use any bundle name and test your app on device with the Team Provisioning Profile:*

Check that whether your certificate is in the certificate list of the Team Provisioning Profile.
If there is not, don't worry. It is managed by Xcode. You can enable it in your Xcode.

Thursday, July 21, 2011

_gzwrite _gzclose referenced from - symbol(s) not found

If you are suffering from this build error
just add framework "libz.dylib" to your iPhone project.

It's a "link" error.
For problems like "xxxx reference from ... symbol(s) not found", try to find the missing framework.

Search the link-error method, and "Jump to Definition", you would probably see what framework it is referencing from.

Sunday, July 10, 2011

Info.plist, Failed to launch simulated application: unknown error

I downloaded an opensource iphone project. Failed to build it.

The error message is

could not read data from '/xxxx/xxxx/xxxx/Info.plist': The file “Info.plist” couldn’t be opened because there is no such file.

Tuesday, March 15, 2011

ASIFormDataRequest Undefined symbols Error, frameworks required

ASIHTTPRequest is a very good open-source project, which help you with complicated http requests.

If you are using  ASIFormDataRequest for the first time. You may find the following error:
Undefined symbols: "_CFHTTPAuthenticationIsValid", referenced from: -[ASIHTTPRequest attemptToApplyProxyCredentialsAndResume] in ASIHTTPRequest.o -[ASIHTTPRequest attemptToApplyCredentialsAndResume] in ASIHTTPRequest.o
..........

Sunday, March 13, 2011

cocoahttpserver HTTP Server File Upload on iPhone

Previous Post :
HTTP Web Server, File Upload on iphone

----- Update 20140729 -------

The original googlecode link is removed.

Please check this https://github.com/vodkhang/CocoaHTTPServer-Iphone
http://vodkhang.com/software-development/cocoa-http-server-bug-fix

---------------------------------------------
Let's try cocoahttpserver
we can get it from google code: code.google.com/p/cocoahttpserver/

we focus on iphone project, so just try the iphone sample code.
Get a local copy of the cocoahttpserver repository with this command:
hg clone https://cocoahttpserver.googlecode.com/hg/ cocoahttpserver

Try the iPhoneHTTPServer sample

Tuesday, March 08, 2011

HTTP Web Server, File Upload on iphone

I installed "PDF Reader Lite" on my iphone. There is very amazing function that I can upload files into the app through a http web server on the iphone. How can they do that?

I google and baidu, and get some clues about setting up a http server for a iphone app.

There are some projects about http server on iphone...

Sunday, March 06, 2011

What New Features iOS 4.3


Safari Performance

The Nitro JavaScript engine that Apple pioneered on the desktop is now built into iOS. Using just-in-time compilation, this powerful engine more than doubles the performance of JavaScript execution. Use this power to optimize your webpage or app web view for increased interactivity and responsiveness.

Wednesday, January 26, 2011

Not enough frames in stack, framework unavailable

Error Message: "mi_cmd_stack_list_frames: Not enough frames in stack"
when debugging on a lower-version iOS device.

To solve this problem, go to menu "Project"-> target info ->

Monday, January 03, 2011

NSDateFormatter setDateFormat YYYY return wrong year

On the first day of 2011, I found that the date formatter return a wrong year.
2011-01-01 is converted ot "2010年01月01日"
while 2011-01-02 ,2011-01-03 is converted correctly.

It's because the format string YYYY represent the "Year (of "Week of Year"), used in ISO year-week calendar. May differ from calendar year."


Monday, December 13, 2010

NSDateFormatter:Convert NSDate to NSString description

Convert a NSDate to string in format "yyyy-MM-dd"

NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
NSString *dateString = [dateFormatter stringFromDate:[NSDate date]];
NSLog(dateString);

Saturday, December 11, 2010

iPhone Simulator (IndigoDevice) Internal Error

I got a strange "Internal Error" when building app with Xcode. Restarting Xcode and my Mac do not help. Finally, I found the solution from JPoz:
http://blog.jpoz.net/2009/05/24/iPhone-simulator-internal-error.html
"go into your (username)/Library/Application Support/ and delete the iPhone Simulator folder. Restart xcode and build your app."
It works fine and help a lot.

Thursday, November 25, 2010

Invisible UIActivityIndicatorView loading activity indicator on iPhone4

I found that a UIActivityIndicatorView is invisible on iphone4 while it's working fine on simulator or earlier iphone version. And it's because "UIActivityIndicatorViewStyleWhiteLarge" is invisible on white background on iphone4. After change style to "UIActivityIndicatorViewStyleGray", it shows up but no "large" option.

Tuesday, November 23, 2010

Push Notification:iPhone deviceToken convert to NSString

Here's how to convert the (NSData *)deviceToken to (NSString *):
NSString *deviceTokenString = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
// also remove the space
deviceTokenString = [deviceTokenString stringByReplacingOccurrencesOfString:@" " withString:@""];

Monday, June 29, 2009

Using SoundEngine from apple

Sound Engine 2.0.3 from
http://stormyprods.com/SoundEngine/

Barebones Usage Example

#import 

UInt32     bangSound;