Push Notification in Iphone application [closed] - iphone

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);
}

Related

how to call a function returning bool value on button's click in xcode? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I am new to the ios development, I am just trying to create a simple application for calculations, So for that i have used to textboxes and i want to allow only the numeric values for these. i have already set the keyboard property to numeric pad. Now i want to do it programmatically for that i found the following function from checks for the String contains Numeric value only
+(BOOL) checkforNumeric:(NSString*) str
{
NSString *strMatchstring=#"\\b([0-9%_.+\\-]+)\\b";
NSPredicate *textpredicate=[NSPredicate predicateWithFormat:#"SELF MATCHES %#", strMatchstring];
if(![textpredicate evaluateWithObject:str])
{
//////NSLog(#"Invalid email address found");
UIAlertView *objAlert = [[UIAlertView alloc] initWithTitle:APP_NAME message:#"please enter valid text." delegate:nil cancelButtonTitle:nil otherButtonTitles:#"Close",nil];
[objAlert show];
[objAlert release];
return FALSE;
}
return TRUE;
}
Now i want to call it on button's click, i have tried some ways but it always shows error.
Please help me how can i utilize this function in button's click.
My Actual code of button is:
-(IBAction)button{
if (firstValue.text.length>0 && secondvalue.text.length>0) {
label.text= [ [NSString alloc] initWithFormat:#"Result is: %.2f", ([firstValue.text floatValue]) * ([secondvalue.text floatValue])];
}
else if (firstValue.text.length==0 && secondvalue.text.length==0){
//label.text= #"please enter the values.";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Alert" message:#"Please Enetr First Value and second value." delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alert show];
[alert release];
}else if (firstValue.text.length==0) {
//label.text= #"please enter the first values.";
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:#"Alert" message:#"Please Enter First Value" delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alert show];
[alert release];
}else if (secondvalue.text.length==0) {
//label.text= #"please enter the second values.";
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:#"Alert" message:#"Please Eneter Second Value" delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
Please help me.
I have tried the following ways for this:
BOOL *test= checkforNumeric(firstValue.text);
call your Method like this
BOOL isValidString_withNoNumbers = [self checkforNumeric: firstValue.text];
if(isValidString_withNoNumbers)
{
//your code
}
and also you should change the method to instance method
so it should be
-(BOOL) checkforNumeric:(NSString*) str // - for instance method //+ for class methods
Make your following line this way :-
-(BOOL) checkforNumeric:(NSString*) str
and declare it in your .h file
if your method is in the same class, you must redifine your method, with -
-(BOOL) checkforNumeric:(NSString*) str
and call it with:
[self checkforNumeric: firstValue.text];
if you define +(BOOL) checkforNumeric:(NSString*) str in another class like MyCheckClass,
you must import MycheckClass and call it:
BOOL isOk = [MyCheckClass checkforNumeric:firstValue.text];

UIAlertView if Login or Password are empty [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I'm creating simple login page where AlertView needed to be shown if password or login fields are empty.Could anyone help me with that?
-(void)login{
if(username.text.length == 0 || password.text.length == 0){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Complete All Fields" message:#"You must complete all fields to login!" delegate:self cancelButtonTitle:#"Okay" otherButtonTitles:nil, nil];
[alert show];
[alert release]
}
}
This should do it. -(void)login is the method attached to some touch event, such as when the user taps a "login" button or something.
username and password are UITextFields.
This problems boils down to two major subproblems;
How to check if a string is empty
NSString offers a method called length which will return the number of characters within that string instance.
NSString Reference:
length
Returns the number of Unicode characters in the receiver.
- (NSUInteger)length
Return Value
The number of Unicode characters in the receiver.
Discussion
The number returned includes the individual characters of composed character sequences, so you cannot use this method to determine if a string will be visible when printed or how long it will appear.
Assuming that there is a variable existing called name of type NSString.
if ([name length] == 0)
{
NSLog(#"the given name is empty!");
}
How to display an alert
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Login Error"
message:#"The given name is empty."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
For more, see the UIAlertView Reference.

How to fetch data from server? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 11 years ago.
I am making an login application in which user can log in.
If the user has already register, then he should be able to log in with the same data saved on server and should be able to get alert view as success and if not the error alert.
Unfortunately, I am not able to do that.
Please help me out.
This is my code:
-(IBAction)btn_login: (id) sender
{
NSString *firstname = Firstname.text;
NSString *lastname = Lastname.text;
NSString *post = [NSString stringWithFormat:#"fname=%#&lname=%#",firstname,lastname];
NSString *hostStr =#"http://www.yoursite.com/iphone.php";
hostStr = [hostStr stringByAppendingString:post];
NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:hostStr]];
NSString *serverOutput = [[NSString alloc]initWithData:dataURL encoding:NSASCIIStringEncoding];
if ([serverOutput isEqualToString:#"Yes"])
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Congrats" message:#"You are authorised" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil,nil];
[alert show];
[alert release];
}
else {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Error" message:#"Invalid Username and password" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil,nil];
[alert show];
[alert release];
}
Firstname.text=nil;
Lastname.text=nil;
}
thanks
You need to supply a "?" after the address when appending parameters.
Change
NSString *hostStr=#"http://www.yoursite.com/iphone.php";
to
NSString *hostStr=#"http://www.yoursite.com/iphone.php?";
PS: NSData dataWithContentsOfUrl is a horrible way to do this. Use NSURLConnection and use authentication challenge for Basic Authentication. Read URL Loading System Programming Guide.

Bluetooth warnings Xcode?

I'm trying to learn about using bluetooth connectivity through making a simple peer to peer bluetooth chat app. I'm hitting a bit of a problem as I'm new to exploring GameKit and Bluetooth and am hoping someone can help me. I think it's a formatting issue, but I could be very wrong. Basically when sending messages between both devices I'd like to use the name of the device that the message is coming from in the UIAlertView popup that displays the message. For example, 'Johnny's Iphone says:...'
Here's the bit of my code dealing with the AlertVIew:
- (void) receiveData:(NSData *)data
fromPeer:(NSString *)peer
inSession:(GKSession *)session
context:(void *)context {
//---convert the NSData to NSString---
NSString* str;
str = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:(#"Chat Message: %#", peer)
message:str
delegate:self
cancelButtonTitle:#"REPLY"
otherButtonTitles:nil];
[alert show];
[alert release];
}
In the above I'm trying to use 'peer' to set the name but it's not working. I've tried initialising peer as a string and then passing it but this isn't working either. In both cases I get a string of 9 or 10 numbers with whatever message was sent displayed below. Where am I going wrong and what should I be doing?
Use [session displayNameForPeer:peer] which will return you the "display name"

handleOpenURL not called using a custom url schema in iPhone OS

I have successfuly added my own url schemes to my App. The App correctly launches using the schemes.
Now I want to handle the incoming data but the delegate is not called. It is an universal app and I have added the following function to both AppDelegates:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
if (!url) { return NO; }
NSString *URLString = [url absoluteString];
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:NSLocalizedString(#"test message", nil)
message:URLString
delegate:self
cancelButtonTitle:nil otherButtonTitles:#"OK", nil];
[alert show];
[alert release];
return YES;
}
I am testing with a schema like: myapp://appalarm.com
…and would expect to be appalarm.com in the URLString
What is wrong with it?
Thanks for your responses!
I tried to clarify in another post. The answer of Ashley Clark is only partly correct. Under OS 4.0 the handleOpenURL gets called (at least for file URLs) and you have to implement it to handle open url calls for when the app is in background. Thus, opening the file in both methods may open it twice (if applicationDidFinishLaunchingWithOptions returned YES, which it should). See another post.
If your application delegate has implemented 'applicationDidFinishLaunchingWithOptions:' then the 'handleOpenURL:' method will never be called. Look at the options passed in through the other method to determine how your app was launched and what behavior you should implement.
Try your code into below function
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
if (!url) { return NO; }
NSString *URLString = [url absoluteString];
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:NSLocalizedString(#"test message", nil)
message:URLString
delegate:self
cancelButtonTitle:nil otherButtonTitles:#"OK", nil];
[alert show];
[alert release];
return YES;
}