如何通过在fb上发布消息来实现计划事件 [英] How implement scheduling event with post a message on fb

查看:55
本文介绍了如何通过在fb上发布消息来实现计划事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个应用程序,其中添加了用于在您的帐户上发布消息的功能.现在,我正在为该设施添加一个用于计划的事件.在该用户的帮助下,您可以编写一条消息并稍后或在特定的日期和时间发布该消息.为此,我使用了本地通知事件,该事件由用户在给定日期生成.但是问题是,当生成通知时,我已经调用了一个用于在Facebook上发布帖子的函数.为了生成通知,我使用了以下代码:

I am creating an application in which I have add a facility for post message on ur account. Now this facility I am adding an event for scheduling. With help of that user can write a message and post that later or on particular date and time. For this I used a local notification event which is generate on given date by user. But problem is that when notification generate then I have call a function which is used for post message on Facebook. For generate notification I have used this code:

-(IBAction)save{
    NSString *str1=[NSString stringWithFormat:@"%@",txt_date.text];
    NSString *str2=[NSString stringWithFormat:@" %@",txt_time.text];
    str1=[str1 stringByAppendingFormat:str2];
    selected_label.text= str1;
    [[UIApplication sharedApplication] cancelAllLocalNotifications];
    NSDate *today=[NSDate date]; 
    NSDateFormatter* formatter_current = [[[NSDateFormatter alloc] init] autorelease];
    formatter_current.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
    //Set the required date format 
    [formatter_current setDateFormat:@"yyyy-MM-dd hh:mm a"]; 

    NSLog(@"current date is =%@",str1); 
    today=[formatter_current dateFromString:str1];
    NSLog(@"current date:-%@",today); 
    UILocalNotification* ln = [[UILocalNotification alloc] init];
    ln.alertBody = @"Wake Up Sid";
    ln.applicationIconBadgeNumber = 1;
    ln.fireDate = today; //[NSDate dateWithTimeIntervalSinceNow:15];
    ln.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
    NSLog(@"alarm will activate on%@",today);
    NSDateFormatter* formatter_alarm = [[[NSDateFormatter alloc] init] autorelease];
    NSLocale *uslocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
    [formatter_alarm setLocale:uslocale];
    [uslocale release]; 
    formatter_alarm.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
    [formatter_alarm setDateFormat:@"hh:mm a"]; 
    NSString *str=[formatter_alarm stringFromDate:today];
    NSLog(@"%@",str);
    ln.alertBody = [NSString stringWithFormat:@"Your first appointment at %@",str];
    ln.soundName = UILocalNotificationDefaultSoundName;
    ln.repeatInterval=NSDayCalendarUnit;
    [[UIApplication sharedApplication] scheduleLocalNotification:ln];
    [ln release];
}

在appdelegate文件中,我将此功能用于接收通知和呼叫后消息功能:

and in appdelegate file I use this function for received notification and call post message function:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
// Override point for customization after application launch.

    self.viewController=[[demo_social_updatesViewController alloc]initWithNibName:@"demo_social_updatesViewController" bundle:nil];
    nav_controller=[[UINavigationController alloc] initWithRootViewController:self.viewController];
    // Add the view controller's view to the window and display.
    [self.window addSubview:nav_controller.view];
    [self.window makeKeyAndVisible];
    appDelegate_acess_token=[[NSUserDefaults standardUserDefaults] stringForKey:@"access_token"];
      application.applicationIconBadgeNumber = 0;
    // Handle launching from a notification
    UILocalNotification *localNotif =
    [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
    if (localNotif) {
        NSLog(@"Recieved Notification %@",localNotif);
    }
    return YES;
}

- (void)applicationDidEnterBackground:(UIApplication *)application{
    if (application.applicationIconBadgeNumber == 1) {
        BOOL tmp=[Global_Class_parsing post_comment_fb:appDelegate_acess_token uesr_comment:@"testing message111"];
        if(tmp){

            UIAlertView *av = [[[UIAlertView alloc] initWithTitle:@"Sucessfully posted to photos & wall!" 
                                                          message:@"Check out your Facebook to see!"
                                                         delegate:nil 
                                                cancelButtonTitle:@"OK"
                                                otherButtonTitles:nil] autorelease];
            [av show];

        }
        else{
            UIAlertView *av = [[[UIAlertView alloc] initWithTitle:@"error"message:@"Check connection!"
                                                         delegate:nil 
                                                cancelButtonTitle:@"OK"
                                                otherButtonTitles:nil] autorelease];
            [av show];
        }
    }

    /*
     Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
     If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
     */
}

- (void)applicationWillEnterForeground:(UIApplication *)application{
    /*
     Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
     */
    if (application.applicationIconBadgeNumber == 1) {
        BOOL tmp=[Global_Class_parsing post_comment_fb:appDelegate_acess_token uesr_comment:@"testing message111"];
        if(tmp){

            UIAlertView *av = [[[UIAlertView alloc] initWithTitle:@"Sucessfully posted to photos & wall!" 
                                                          message:@"Check out your Facebook to see!"
                                                         delegate:nil 
                                                cancelButtonTitle:@"OK"
                                                otherButtonTitles:nil] autorelease];
            [av show];

        }
        else{
            UIAlertView *av = [[[UIAlertView alloc] initWithTitle:@"error"message:@"Check connection!"
                                                         delegate:nil 
                                                cancelButtonTitle:@"OK"
                                                otherButtonTitles:nil] autorelease];
            [av show];
        }
    }
}

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
    UIApplicationState state = [application applicationState];
    if (state == UIApplicationStateInactive) {
        NSLog(@"Recieved Notification %@",notification);
    } else {
        NSLog(@"Recieved Notification method call.");
    }
}

现在的问题是,当通知生成且applicationbadge编号变为1时,它不会调用任何函数,而我的帖子功能也不会调用.那么我该如何解决该错误?

Now problem is that when notification generate and applicationbadge number become 1 then it not call any function and my post message function not calling. So how I fix that error?

推荐答案

对于此问题,我得到的解决方案是我有两种方法可以通过post方法实现调度,一种是简单地使用通知.另一个是使用网络服务.我都用过并且工作良好.

I get solution for this question is that i have two way to implement scheduling with post method one is simply use notification. And another is use web-service. I have used both and working well.

这篇关于如何通过在fb上发布消息来实现计划事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆