Wcsession session expired and error 7007 - swift

I am new in WatchKit and I am working on one of my app, but I am facing one problem regarding connection with Apple watch.
my source code is below:
-(BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{ //create a session using wcsession
if ([WCSession isSupported]) {
[[WCSession defaultSession] setDelegate:self];
[[WCSession defaultSession] activateSession];
}
return YES;
}
Send message action in my viewcontroller:
[[WCSession defaultSession] sendMessage:dict replyHandler:^(NSDictionary *replyHandler)
{
NSLog(#"Replay %#",replyHandler);
}
errorHandler:^(NSError *error) {
NSLog(#"Error %#",error);
}];
Also I activate the wcsession at watch side in complication controller
]if ([WCSession isSupported]) {
[[WCSession defaultSession] setDelegate:self];
[[WCSession defaultSession] activateSession];
}
and
-(void)session:(nonnull WCSession *)session
didReceiveMessage:(nonnull NSDictionary<NSString *,id> *)message
replyHandler:(nonnull void (^)(NSDictionary<NSString *,id> * __nonnull))replyHandler {
[extensionDelgate InsertIntoTideMaster:message];
[self requestedUpdateDidBegin];
dispatch_async(dispatch_get_main_queue(), ^{
});
}
This works first time when I am launching the app, but after that I got 7007 code error ... can you tell me what is missing here?
Thanks in advance.

Related

Disable UrbanAirship alerts

I want to ignore push notifications when the app is active. I am handling notifications as follows:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
if (application.applicationState != UIApplicationStateActive)
{
[[PushHelper shared] processPush: userInfo];
}
}
But when app is active and device receives push notification, the UIAlertView with notification message appears. How can I disable default handling from UA?
I had the same problem and found solution.
If define the delegate method displayNotificationAlert: of UAPushNotificationDelegate protocol with empty body, for example, then the automatic alerts will not be shown:
{
...
[[UAPush shared] registerForRemoteNotifications];
[UAPush shared].pushNotificationDelegate = self;
...
}
- (void)displayNotificationAlert:(NSString *)alertMessage
{
}
If you don't need to do anything with the push notification itself just remove the [[PushHelper shared] processPush: userInfo] from your code
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
//nothing to do here
}
The didReceiveRemoteNotification method is only called when the app is running.

Facebook integration using parse framework

I done Facebook integration using parse framework with my application so how can i add logout button as well as permission to the user below mentioned image is my application screen-short as well how can i obtain okay button pressed event in my code..?
Login
In your app delegate, these lines should be present:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[Parse setApplicationId:#"YOUR_APPLICATION_ID"
clientKey:#"YOUR_CLIENT_KEY"];
[PFFacebookUtils initializeWithApplicationId:#"YOUR_FB_APP_ID"];
// Override point for customization after application launch.
return YES;
}
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [PFFacebookUtils handleOpenURL:url];
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [PFFacebookUtils handleOpenURL:url];
}
This will ensure that parse is initialized and connected with your facebook app on startup. The two methods at the bottom are what enables your app to launch the screen to sign in to facebook and request permissions. In order to actually present that screen to the user, all that's necessary is a button that calls a method similar to this one:
-(IBAction)facebookLoginButtonPressed:(id)sender {
[self loginWithFacebook];
}
-(void)loginWithFacebook {
NSArray *permissionsArray = #[#"publish_actions", #"email", #"user_location"];
// Login PFUser using Facebook
[PFFacebookUtils logInWithPermissions:permissionsArray block:^(PFUser *user, NSError *error) {
if (!user) {
if (!error) {
NSLog(#"Uh oh. The user cancelled the Facebook login.");
} else {
NSLog(#"Uh oh. An error occurred: %#", error);
}
} else {
[self performSegueWithIdentifier:#"loginToFeed" sender:self];
}
}];
}
You shouldn't need an event callback for the ok, when the [PFFacebookUtils logInWithPermissions:block:] comes back, it will perform the block that you provide, enabling you to segue to different ViewControllers or show different features.
Log Out
Add a button to whatever view you want to have control logging out. Then add an IBAction method for that button:
-(IBAction)logOutButtonPressed:(id)sender {
[PFUser logOut];
NSLog(#"User logged out!");
[self dismissViewControllerAnimated:YES completion:^{}];
}

How do I respond to successful login with Dropbox API on iOS?

It checks whether the user is logged into dropbox when my app is launched. If they are, it continues with code relating to dropbox. If not, it shows them a login screen using [[DBSession sharedSession] link];.
From the login screen comes this delegate, if authorization fails:
-(void)sessionDidReceiveAuthorizationFailure:(DBSession *)session userId:(NSString *)userId {
[[DBSession sharedSession] link];
}
But there doesn't seem to be something for when authorization succeeds. How do I deal with this scenario? I need to start running the necessary code once they're linked with dropbox.
You handle successful login from the Dropbox API in the
-(BOOL) application:(UIApplication *)application handleOpenURL:(NSURL *)url function
-(BOOL) application:(UIApplication *)application handleOpenURL:(NSURL *)url {
if ([[DBSession sharedSession] handleOpenURL:url]) {
//Successfully Logged in to Dropbox
return YES;
}
return NO;
}
As part of applicationDidFinishLaunching you could initiate the dropbox api you could do the following.
dispatch_async(dispatch_get_main_queue(), ^{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
DBSession* dbSession = [[[DBSession alloc] initWithAppKey:#"appKey" appSecret:#"appSecret" root:kDBRootAppFolder] autorelease];
dbSession.delegate = self;
[DBSession setSharedSession:dbSession];
[[NSNotificationCenter defaultCenter] postNotificationName:kSharedSessionAvailability object:[NSNumber numberWithBool:dbSession != nil ? YES : NO]];
});
But normally you simply get your session and use it later via the restClient.

Local Notification in foreground in iPhone SDK

Will the local notification show up when the app is in foreground and currently running in iPhone SDK?
No, you will receive a the notification in the appdelegate.
- (void) application:(UIApplication *)application didReceiveLocalNotification: (UILocalNotification *)notification {
//Place your code to handle the notification here.
}
I made an lib to make an animation almost as same as local notification's.
Check this:
https://github.com/OpenFibers/OTNotification
Demo:
And you can post a new message to this lib when you received a message in
- (void) application:(UIApplication *)application didReceiveLocalNotification: (UILocalNotification *)notification
{
OTNotificationManager *notificationManager = [OTNotificationManager defaultManager];
OTNotificationMessage *notificationMessage = [[OTNotificationMessage alloc] init];
notificationMessage.title = [self notificationTitle];
notificationMessage.message = #"A notification. Touch me to hide me.";
[notificationManager postNotificationMessage:notificationMessage];
}
The accepted anser is right, but it's not enough to receive all notifications and show something to user from
- (void) application:(UIApplication *)application didReceiveLocalNotification: (UILocalNotification *)notification {
You have to check, is it current notification or not.
Sometimes there is fires another notifications (when you cancel them, for example). So, you have to check, that is what you except:
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
if (fabs([[NSDate date] timeIntervalSinceDate:[notification fireDate]]) <= 0.5f)
{
[[[UIAlertView alloc] initWithTitle:NSLocalizedString(#"Notification alert", #"")
message:notification.alertBody
delegate:self
cancelButtonTitle:#"Ok" otherButtonTitles:nil] show];
}
}
if your app is currently in foreground the following function will be called in your Delegate:
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)Notifikation
you can then decide to show an alertview, but the standard one will not show up by itself
Swift 2.2:
func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification) {
var state = application.applicationState
if state == .Active {
// handle the notification, e.g. show an alert
}
}
Swift 3.0:
func application(_ application: UIApplication, didReceive notification: UILocalNotification) {
var state: UIApplicationState = application.applicationState
if state == .active {
// handle the notification, e.g. show an alert
}
}

iphone: Set badge on a tabbarItem when receiving a PUSH message, when the app is inactive

I have a application that uses PUSH. But I have one problem when the application is inactive/in the background.
When the PUSH messages come and the user clicks on Close, the badge is set on the application-icon.
But I also want to set a badge on a tabBarItem.
I have this code that saves the PUSH
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
if (application.applicationState == UIApplicationStateInactive) {
//Save the PUSH until the app is active.
newPush = [userInfo copy];
}
}
And in:
- (void)applicationDidBecomeActive:(UIApplication *)application
I have the following code:
//Check if there is new PUSH messages.
if (newPush!=nil) {
//There is a new PUSH!
NSInteger badge = [[[newPush objectForKey:#"aps"] objectForKey:#"badge"] intValue];
if (badge > 0) {
//Set badge-numbers to 'badge'
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:badge];
[[[[[self tabBarController] tabBar] items] objectAtIndex:3] setBadgeValue:[NSString stringWithFormat:#"%d",badge]];
}
else {
//Set badge-numbers to zero
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
[[[[[self tabBarController] tabBar] items] objectAtIndex:3] setBadgeValue:nil];
}
}
My code for handling the PUSH when the application is active works fine and the badges are set both on the application-icon and on the tabBarItem.
Someone know what's wrong?
Thanks in advance!
If the application is inactive, didReceiveRemoteNotification is not executed. The only way the notification data can reach your app in this case is if the user taps on the notification to open the app. Then, when the app is launched, you can get the notification data in application:didFinishLaunchingWithOptions: by using this code :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions {
NSDictionary *remoteNotif = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];
//Accept push notification when app is not open
if (remoteNotif) {
[self handleRemoteNotification:application userInfo:remoteNotif];
return YES;
}
return YES;
}