How can i implement apple Push Notification ?? [closed] - iphone

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
i am new in iphone development,i want to implement push Notification in my application. i have no idea about that. anyone give sample code.

Firstly, you have to either rent or own a server that is responsible for communicating with Apple's APNS servers. Yes, when pushing notifications to your app's users, your server has to first push it to Apple and have Apple transfer those notifications to specific users on your behalf.
And second, override and implement the following methods in your AppDelegate's .m file:
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken {
- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error {
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
//You probably already implemented this one
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
And test your code and your server with Apple's Sandbox server before you put your app into production.

Follow Apple's Documentation.

Related

Transfer Data From Apple Watch To iPhone in Swift [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have been trying for multiple hours to find a way to send a global variable from the Apple Watch to the iPhone.
There are a lot of questions abut transferring data from iPhone to Apple Watch but not vice versa in Swift 3.
This is not a duplicate because I want to transfer data from the Apple Watch to iPhone, not vice Versa.
How can I do this?
Transferring data from Apple Watch to iPhone is very similar to vice versa.
For global variable you probably should use updateApplicationContext() of WCSession:
let session = WCSession.default()
if session.activationState == .activated {
session.updateApplicationContext(["my_global": g_myGlobal])
}
On the iPhone you should assign delegate to the default WCSession and activate it. In the WCSessionDelegate, implement the following method:
func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String : Any]) {
let receivedGlobal = applicationContext["my_global"] as? TypeOfTheGlobal
}
Alternatively you can use sendMessage(_:replyHandler:errorHandler:) but this will require iPhone to be reachable.
In general I would recommend you to follow Zak Kautz advice and read about WatchConnectivity. This is the most common way to communicate between watch and phone.
Using the watch connectivity framework, you can implement two-way communication.

Adding Watchkit to existing app - Concerns [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I have an app I'm almost ready to publish. I would like to make a view for the watch for it but just wondering if there is anything I should consider first. From what I can tell if you add Watchkit to an existing iPhone app, it doesn't really affect the app as an iPhone app - is that right? Is there anything that changes on an iPhone app when you add Watchkit other than it will (after launch) show up in the Watch app store as well as the regular app store?
Should I publish first, then add Watchkit, then update? Maybe for purposes of it being published quicker? I'd like to be in the Watch store on launch day, is that possible?
thank you
It depends on your specifications. You can publish first your iPhone app without implement any WatchKit version, and then, update with a new version that includes the WatchKit extension.
You have to take into account that if you start a submission process, you can't start another for the same app until Apple approve or reject your app. Of course, you can reject the submission before Apple notify you, in order to upload your new version.

Tutorial for a Tutorial in IOS7 [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
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
Improve this question
I'm already finishing an app and I would like to make a tutorial embedded in the App, like those that appear as an overlay, explaining the functionality of every button, in the app until the user taps the screen.
Another option could be to show a tutorial the first time a user opens the app, but I don't know how to identify if is the first time a user opens the app.
Does anyone knows a good tutorial that shows how to do this?
Thank you!
Follow this link HERE. Its a tutorial for a tutorial you are trying to create using UIPageViewController.
and here is how you can detect the first time user loads the app:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if ([[NSUserDefaults standardUserDefaults] boolForKey:#"HasLaunchedOnce"])
{
// app already launched
}
else
{
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:#"HasLaunchedOnce"];
[[NSUserDefaults standardUserDefaults] synchronize];
// This is the first launch ever
}
}
Hope this helps!

How to get own device token? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
Is it possible to get your own device token from my own iPhone? I need it because I want to test Push-Notifications...
Thanks
You will need to use the -(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken; method. Below is an example that will output your devices token as well as set it to a string.
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSLog(#"APN device token: %#", deviceToken);
NSString *deviceTokenString = [NSString stringWithFormat:#"%#",deviceToken];
}
But, you should really be doing this already though so that you know where to send the notifications for your users, aren't you?
Edit after further clarification comment:
You weren't very specific at all in your question. To answer your more detailed question, you can't display it. As it is unique for each device AND each app. So your token for AppA is not the same as AppB.
The device token needed for push notification you will have in a callback function if you have subscribed to push notification. Until that not, unless you write doen the previous value.
Note the token for app in development / debug mode it is different from release/ad-hoc mode!!!
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
NSLog(#"My token is: %#", deviceToken);
}
Please look at this tutorial. Also it is not working with simulator, and jailbroken devices

Best practice for applicationDidEnterBackground [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I am in the middle of writing an application that needs to reset certain parts of its state to a default state when the application calls applicationDidEnterBackground. What I would like to know is if it is a better practice to get a pointer to the view that needs to be reset and then reset the properties that need to be reset right there in the app delegate, or should I post an NSNotification that the app is entering the background and have the view controller do it's cleanup within itself. Or maybe there's another method I'm not thinking of.
I appreciate any input.
These notifications get posted already. Just subscribe to the event in your controller class(es) and do whatever you need to there.
From the docs:
The application also posts a
UIApplicationDidEnterBackgroundNotification
notification around the same time it
calls this method to give interested
objects a chance to respond to the
transition.
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIApplication_Class/Reference/Reference.html#//apple_ref/c/data/UIApplicationDidEnterBackgroundNotification