More Story Time
seen from Japan

seen from United States
seen from United States
seen from United Kingdom

seen from United States
seen from China

seen from United States
seen from United States
seen from United States
seen from Türkiye

seen from United Kingdom

seen from Malaysia
seen from China

seen from Germany
seen from Türkiye
seen from United States

seen from United States
seen from United Kingdom
seen from United Kingdom

seen from Russia
More Story Time
iPhone/iPadに溜まっている未読メールを一瞬で既読にする方法 今回は、iPhone/iPadの標準のメールアプリで溜まっている未読のメールを一瞬で既読にする裏技!を紹介します。 それではこちらをご覧下さい! ※iPhoneの画面で説明致しますが、iPadでも可能です。 【メールで受信トレイを開く】 http://touchnavi.net/news/wp-content/uploads/2012/07/IMG_69761.png http://touchnavi.net/news/wp-content/uploads/2012/07/IMG_69771.png 【[編集]ボタンをタップ】 http://touchnavi.net/news/wp-content/uploads/2012/07/IMG_69781.png 【メールをひとつ選択する】 http://touchnavi.net/news/wp-content/uploads/2012/07/IMG_69791.png 【[マーク]ボタンを長押しした状態で、メールの選択を外す】 http://touchnavi.net/news/wp-content/uploads/2012/07/IMG_69801.png 【[マーク]ボタンを離し、[開封済みにする]をタップ】 http://touchnavi.net/news/wp-content/uploads/2012/07/IMG_69801.png 下からメニューが表示されます。[開封済みにする]をタップします。 http://touchnavi.net/news/wp-content/uploads/2012/07/IMG_69831.png すべての未読メールが一気に既読になりました。 http://touchnavi.net/news/wp-content/uploads/2012/07/IMG_69841.png ちなみに、既読メールを選択して今と同じ操作を行うと、 『すべてのメールを未読メールにする』ことも可能です!
http://touchnavi.net/news/?p=1193
iPhone用のSafariで開いているページをChromeから開く javascript:location.href="googlechrome"+location.href.substring(4);
http://www.lifehacker.jp/2012/07/120703chromesafari.html
How to create a Facebook Wrapper class for cocos2d? (I-OS)
As I am working on my new App, I was trying to implement Facebook, so the users can post on their wall, and as I had some trouble I thought I'll make a post on how to do that.
My target was to get as much of the Facebook implementation in one Class as I could get... I called it FacebookHelper Class like the GamkitHelper Class Steffen Itterheim created in his book Learn cocos2d Game Development with iOS 5. I tried to design it as a semi singleton.
So first things first :-) I used a lot of the Facebook Tutorial especially the first few steps:
1. Set up your app on Facebook.
2. Download the Facebook SDK and put the necessary files into your Xcode project. as well as changing the info.plist!
The necessary steps are on the Facebook developer site!
I would like to focus on creating a Facebook Helper Class:
As first step I created the FacebookHelper.h and FacebookHelper.m as an NSObject.
Let's have a look at the FacebookHelper.h:
#import <Foundation/Foundation.h> #import <UIKit/UIKit.h> #import "FBConnect.h" #import "Common.h" @interface FacebookHelper : NSObject<UIApplicationDelegate,FBSessionDelegate,FBDialogDelegate>{ Facebook *facebook;
} @property (nonatomic, retain) Facebook *facebook; +(id)alloc; +(FacebookHelper*) sharedFacebookHelper; -(void)postToWall; @end
Import UIKit and FBConnect.h in my Common.h I store the Facebook Keys:
#define kFacebookAppId @"your App ID" #define kFacebookAppSecret @"Your App Secret"
Add the following delegates <UIApplicationDelegate,FBSessionDelegate,FBDialogDelegate> which are needed later on.
The next step is to create an instance of Facebook including a property.
As I tried to design the class as a semi singleton you need to implement the following methods:
+(id)alloc; +(FacebookHelper*) sharedFacebookHelper;
And to post on the Wall add the -(void)postToWall; as well.
The second part is the FacebookHelper.m:
#import "FacebookHelper.h" @implementation FacebookHelper @synthesize facebook; static FacebookHelper *instanceOfFacebookHelper; #pragma mark Singleton +(FacebookHelper*) sharedFacebookHelper { @synchronized(self) { if (instanceOfFacebookHelper == nil) { [[FacebookHelper alloc] init]; } return instanceOfFacebookHelper; } // to avoid compiler warning return nil; } +(id) alloc { @synchronized(self) { NSAssert(instanceOfFacebookHelper == nil, @"Attempted to allocate a second instance of the singleton: FacebookHelper"); instanceOfFacebookHelper = [[super alloc] retain]; return instanceOfFacebookHelper; } // to avoid compiler warning return nil; } #pragma mark init -(id)init { if ((self = [super init])) { facebook = [[Facebook alloc] initWithAppId:kFacebookAppId andDelegate:self]; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; if ([defaults objectForKey:@"FBAccessTokenKey"] && [defaults objectForKey:@"FBExpirationDateKey"]) { facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"]; facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"]; } NSLog(@"%@",facebook.isSessionValid? @"YES" : @"NO"); if (![facebook isSessionValid]) { [facebook authorize:nil]; } } return self; } #pragma mark - FBSessionDelegate Methods - (void)fbDidLogin { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"]; [defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"]; [defaults synchronize]; NSLog(@"Did Log in!"); [self postToWall]; } - (void)fbDidNotLogin:(BOOL)cancelled{ NSLog(@"No Log in!"); } - (void)fbDidLogout{ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults removeObjectForKey:@"FBAccessTokenKey"]; [defaults removeObjectForKey:@"FBExpirationDateKey"]; [defaults synchronize]; } - (void)fbDidExtendToken:(NSString*)accessToken expiresAt:(NSDate*)expiresAt{ NSLog(@"token extended"); [self storeAuthData:accessToken expiresAt:expiresAt]; } - (void)fbSessionInvalidated{ UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Auth Exception" message:@"Your session has expired." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; [alertView show]; [alertView release]; [self fbDidLogout]; } - (void)storeAuthData:(NSString *)accessToken expiresAt:(NSDate *)expiresAt { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults setObject:accessToken forKey:@"FBAccessTokenKey"]; [defaults setObject:expiresAt forKey:@"FBExpirationDateKey"]; [defaults synchronize]; } -(void)postToWall{ NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys: kFacebookAppId, @"app_id", @"http:// www. yourwebsite. com", @"link", @"http:// www. yourpicture. com/picture.png", @"picture", @"Your Title!", @"name", @"Your caption!", @"caption", @"Your description", @"description", nil]; [facebook dialog:@"feed" andParams:params andDelegate:self]; } #pragma mark dealloc -(void) dealloc { [facebook release]; [instanceOfFacebookHelper release]; instanceOfFacebookHelper = nil; [super dealloc]; } @end
Ok, I will go through the methods one by one and describe what each one does:
Don’t forget to @synthesize facebook…
First I create a static instance of FacebookHelper. This instance will be returned to the calling class.
The +(FacebookHelper*) sharedFacebookHelper and +(id) alloc methods make sure only one Instance of FaceBookHelper is used at all times.
In the init method the facebook variable is initilized with the app id and self as delegate.
Furthermore the access token and the expiry date is accessed from the user defaults:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; if ([defaults objectForKey:@"FBAccessTokenKey"] && [defaults objectForKey:@"FBExpirationDateKey"]) { facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"]; facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"]; }
And it is checked if the session is valid. If not facebook is authorized:
if (![facebook isSessionValid]) { [facebook authorize:nil]; //here is the possibility to ask for more permissions! }
The next few methods are delegate methods for FBConnect:
The fbDidLogin method stores the access token and the expiry date, which can be used to access Facebook next time without extra authorization. In my case I added a call to post here to make it easier for me.
The next one fbDidNotLogin gives you feedback if the user cancelled.
The fbDidLogout handles if the user logs out and removes the access token.
The fbDidExtendToken:(NSString*)accessToken expiresAt:(NSDate*)expiresAt method extends the access token.
The fbSessionInvalidated gives the user feedback if the session was invalidated for some reason.
The storeAuthData method is used to save the extension of the access token.
In the postToWall you can give the information you want to post with the users comment, you can localize the with NSLocalizedString.
The last step is to #import "FacebookHelper.h" in the class you want to call Facebook from.
You can call it like that:
FacebookHelper *facebookHelper = [FacebookHelper sharedFacebookHelper]; NSLog(@"%@",facebookHelper.description); if (facebookHelper.facebook.isSessionValid) { [facebookHelper saveScore:scoreVal]; [facebookHelper postToWall]; }
Ok, that was a long post, I hope it helps you to implement Facebook in your App. As you see you can expand the class to your liking... and add more features. As this is my first tutorial, I would appreciate some feedback and would be happy to add your suggestions...
Next time I plan to make a tutorial of my Twitter Helper class with I-OS 5 support and I-OS 4 fallback. So stay tuned...