Existing program doesn't run on iOS5 [closed] - ios5

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
Two of my programs available in the AppStore for months and running without any problems on iOS3 and iOS4 are not compatible with iOS5.
It seems to me that Apple has changed some things to make the life of developers a little bit harder.
One of the problems is this:
- (BOOL) webView: (UIWebView *) webView shouldStartLoadWithRequest:(NSURLRequest *) request navigationType: (UIWebViewNavigationType) navigationType {
// Only do something if a link has been clicked
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
NSString *link = [[request URL] absoluteString];
if ([link hasPrefix:#"playSound:"]) {
[PlayAudio playAudio: [link substringFromIndex:10]];
return NO;
}
}
return YES;
}
The line that make the problem is
NSString *link = [[request URL] absoluteString];
Before I got an unmodified copy of the clicked link. In iOS3 and iOS4 it is still the same. But on iOS5 it is converted to lowercase only.
The next Line
if ([link hasPrefix:#"playSound:"]) {
never becomes true. So I had to change the code to
- (BOOL) webView: (UIWebView *) webView shouldStartLoadWithRequest:(NSURLRequest *) request navigationType: (UIWebViewNavigationType) navigationType {
// Only do something if a link has been clicked
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
NSString *link = [[[request URL] absoluteString] lowercaseString];
if ([link hasPrefix:#"playsound:"]) {
[PlayAudio playAudio: [link substringFromIndex:10]];
return NO;
}
}
return YES;
}
Now I'm expecting lowercase on all versions of iOS and therefore compare with a lowercase string.
What do you think: Are changes like this on a new iOS version neccessary?

Related

How can I obtain the HTTP status when accessing NSURLConnection or the like? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I would like to make preferably synchronous (but otherwise Ajax-like) calls to a server on iOS, presumably using NSURLConnection. Or at least synchronous in some cases.
I am interested in the status code on a response. How can I access the status code for a response to an NSURLConnection?
Any sample code or tutorial links would be welcome; https://developer.apple.com/library/ios/documentation/cocoa/reference/foundation/Classes/NSURLResponse_Class/Reference/Reference.html#//apple_ref/doc/c_ref/NSURLResponse is the best I'm going off of now.
you can use delegate function of nsurlconnection deleate class by this
(void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
int code = [(NSHTTPURLResponse *)response statusCode];
if (code == 404)
{
// website not found
/ / do your stuff according to your need
}
}
or while sending synchronous request you can check status code like
id response2 = nil;
NSError *error1 = nil;
NSData *receivedData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error1];
//and then check the above response status code like
int code = [(NSHTTPURLResponse *)response2 statusCode];
if (code == 404)
{
// website not found
/ / do your stuff according to your need
}
For Synchronous request you can get the response code like this
NSError *error = nil;
NSHTTPURLResponse *responseCode = nil;
NSURLRequest *request;
NSData *oResponseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&responseCode error:&error];
int code = [responseCode statusCode];

Something wrong with my variable [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
I created a getter to get the content of a variable, but it doesn't works.
Here the code:
-(void)documentURLReceived:(NSURL *)url{
_getUrl = [[NSURL alloc] init];
_getUrl = url;
NSLog(#"Result: %#", _getUrl);
}
-(void)getUrl{
NSLog(#"getUrl: %#", _getUrl);
}
Here the result in the consol:
Result: http://www.google.com
getUrl : (null)
I don't understand why!
Here my property:
#property (strong, nonatomic) NSURL *getUrl;
Thanks for your help :)
If you are using ARC and the latest Xcode - get rid of the getURL method - you should not be overwriting this unless you need to do custom logic, furthermore, your getURL method returns nothing and is a void method - so the variable is most likely set but your method is overwriting the automatically generated getter and is returning nothing.
Did a test in Xcode
In header file I have:
#property (nonatomic, strong) NSURL *getURL;
and then in implementation file I have:
- (void)documentURLReceived:(NSURL *)url
{
_getURL = url;
NSLog(#"%#",_getURL);
}
which outputs:
2013-04-04 23:29:27.681 VitalityDesignTestSuite[90518:c07]
http://www.google.com
okie dokie I wrote you a sample:
http://bit.ly/10yWb36
to use those you can go:
MyViewController *mvc = [[MyViewController alloc] initWithNibName:#"MyViewController" bundle:nil];
//Now you can set the myURL variable directly
[mvc setMyURL:[NSURL URLWithString:#"http://www.google.com"]];
NSLog(#"Direct Setting: %#",mvc.myURL);
//OR you can call the method your wrote
[mvc documentDidReceiveURL:[NSURL URLWithString:#"http://www.google.com"]];
NSLog(#"Selector Setting: %#",mvc.myURL);
that outputs:
2013-04-04 23:39:09.407 VitalityDesign[92197:c07] Direct Setting: http://www.google.com
2013-04-04 23:39:09.408 VitalityDesign[92197:c07] Selector Setting: http://www.google.com
hope this helps
First of all are you getting anything in url?
If No, -> Work over it
If yes then, try to do following:
_getUrl = [[NSURL alloc] init];
_getUrl = url;
[_getUrl retain];
NSLog(#"Result: %#", _getUrl);
Enjoy Programming!

No visible #interface for 'NSString' declares the selector 'appendData' [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I am trying to call the server asynchronously (ARC -on):
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self];
if (theConnection) {
content = [NSMutableData data];
NSLog(#"responseData from setup.php: %#", content);
} else {
// Inform the user that the connection failed.
NSLog(#"error from server response in set up");
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
NSLog(#"connection did receive response");
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[content appendData:data];
NSLog(#"connection did receive data");
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(#"connection did finish load");
NSLog(#"Succeeded! Received %# bytes of data",receivedData);
}
But i am having problem getting the content from the server:-
in didReceiveData function, following error is coming:-
No visible #interface for 'NSString' declares the selector 'appendData'
Can anybody suggest me where I could be wrong?
in your .h file in the interface section please declare the following
NSMutableData *content;

uniqueIdentifier deprecated, example from Cocos2d

I have searched the web for the answer and have found quite a few solutions but have to admit i do not really understand, as i am pretty new, how to apply the answer, one example is: UIDevice uniqueIdentifier Deprecated - What To Do Now?
I would really appreciate if someone could show me an example how to apply the solution to the problem in the code below as the following line is deprecated (uniqueIdentifier), the code line is from Cocos2d CLScoreServerRequest.m but comes up in a few others as well:
device = [[UIDevice currentDevice] uniqueIdentifier];
The function looks like:
-(BOOL) requestScores:(tQueryType)type
limit:(int)limit
offset:(int)offset
flags:(tQueryFlags)flags
category:(NSString*)category
{
// create the request
[receivedData setLength:0];
// it's not a call for rank
reqRankOnly = NO;
NSString *device = #"";
if( flags & kQueryFlagByDevice )
device = [[UIDevice currentDevice] uniqueIdentifier];
// arguments:
// query: type of query
// limit: how many scores are being requested. Default is 25. Maximun is 100
// offset: offset of the scores
// flags: bring only country scores, world scores, etc.
// category: string user defined string used to filter
NSString *url= [NSString stringWithFormat:#"%#?gamename=%#&querytype=%d&offset=%d&limit=%d&flags=%d&category=%#&device=%#",
SCORE_SERVER_REQUEST_URL,
gameName,
type,
offset,
limit,
flags,
[category stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding],
device
];
// NSLog(#"%#", url);
NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL URLWithString:url]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:10.0];
// create the connection with the request
// and start loading the data
self.connection=[NSURLConnection connectionWithRequest:request delegate:self];
if (! connection_)
return NO;
return YES;
}
Here's the quick and simple solution:
Change your project's (or target's) deployment target to iOS 4.x or lower. In that case the compiler will still issue a warning but it will be just a warning. Only if your deployment target it iOS 5.0 or newer will the compiler generate an error about the deprecated method.
As for the warnings within the Cocos2D source code, ignore those warnings until the next Cocos2D official release fixes that issue.
you could do:
CFUUIDRef uuidRef = CFUUIDCreate(kCFAllocatorDefault);
if(uuidRef)
{
device = (NSString *) CFUUIDCreateString(kCFAllocatorDefault, uuid);
CFRelease(uuidRef);
} else {
// it's almost 100% likely you won't end up here but
// you should still do something with device (like throw an alert or NSLog)
}
And I just noticed this answer can also be found in this related question.
B.T.W., this UUID will not persist (or be the same) if the app is uninstalled and reinstalled on a device. If you want something like that, you incorporate the code found at:
https://github.com/gekitz/UIDevice-with-UniqueIdentifier-for-iOS-5
Except in this case, there's apparently a tough license agreement.

Push Notification in Iphone application [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I need to implement push notification in my application.
Actually i have to receive messages from the server.
Kindly guide me how i can implement push notifications in my iphone application.
The client side stuff is easy, but if you want a good example we provide one that you can download http://bitbucket.org/urbanairship/push_sample/
You'll find the server side stuff to be a lot more difficult and for that I would recommend using Urban Airship because we provide a simple RESTful service you can use with lots of add-on features and the indie package is free.
http://urbanairship.com/docs/push_index.html
caveat: I work there.
you need to implement these 2 delegate method in your application
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
//NSLog(#"Entered into Method");
NSString *myDevTokenString = [devToken description];
NSLog(myDevTokenString);
self.tokenAsString = [[devToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:#"<>"]];
NSLog(#"token As String:%#", tokenAsString);
//const void *devTokenBytes = [devToken bytes];
//NSLog(#"My Token is : %#",devToken);
//self.registered = YES;
// UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:#"APNClient-GotToken" message:myDevTokenString delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
// [myAlert show];
// [myAlert release];
//[self sendProviderDeviceToken:devTokenBytes]; // custom method
}
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
//UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:#"APNClient" message:#"called -Error- Method" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
// [myAlert show];
// [myAlert release];
NSString *errText = [[NSString alloc] initWithFormat:#"APN Error:%#",err];
NSLog(#"Error in registration. Error: %#", errText);
}