OneSignal Push Notification with Android Studio practice log

It took me one night to make it work, so I’d like to write it down for next time.

Main Flow as follow diagram:

MainFlowchart

Green fields means “what values you can get”

White fields means “what values you should set”

And following are screeshots for each steps

1.Google Developer Console (GCM)

Get these two values.

GoogleDeveloperConsole

2.Set the Server API Key in OneSignal

Set  OneSignal「Server API Key」to 「Server API Key」in Step 1

OneSignal_ServerAPIKEY

3.Set the Project number in Android Studio MainFest.xml (onesignal_google_project_number)

Set the onesignal_google_project_number to 「Sender ID」in Step 1

AndroidStudio_bundlegradle_app

4.Onesignal (App Settings -> Keys & IDs)

Get these values.

OneSignal_appid

5.Set the OneSignal App ID in Android Studio MainFest.xml (onesignal_app_id)

Set the onesignal_app_id to 「OneSignal App ID」in Step 4

AndroidStudio_bundlegradle_app

6.Include libraries in Android Studio

This is according to the OneSignal document

AndroidStudio_bundlegradle_app_dependencies

 

Basically this is all you have to do to send push notification to Android devices via OneSignal and Android Studio.

By the way, I used to use the CUrl script provided by OneSignal to test sending notification, here’s a sample for your reference.

7.CUrl script

There are two fields to be set.

「Authorization Basic」 : set to 「REST API Key」in Step 4

「app_id」: set to 「OneSignal App ID」in Step 4

Curl_CommandLine

 

That’s all, happy pushing !!

Posted in Android | Tagged , , , , , , , | Leave a comment

Facebook Signin Practice Log

Facebook signin ios

Follow the official document procedure
https://developers.facebook.com/docs/facebook-login/ios

1.Download SDK and setup the environment
https://developers.facebook.com/docs/ios/getting-started

Create new Facebook app
1.FB app 2 of 2

1.FB app 1 of 2

2.Configure the XCode project parameters
Info.plist

2.InfoPlist

For AppTransportSecurity parameters, you can follow the Facebook direction, or you can just “allow all” as follow

<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>

3.Modify the source code

3.1 AppDelegate
#import <FBSDKCoreKit/FBSDKCoreKit.h>

– (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
….
}

3.2 ViewController you want to do Facebook Signin
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>

-(void)loginAsFacebook {
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions:  @[@”public_profile”, @”email”, @”user_friends”] fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
NSLog(@”Process error”);
} else if (result.isCancelled) {
NSLog(@”Cancelled”);
} else {
NSLog(@”Logged in”);

NSLog(@”[%@][%@][%@][%@]”, [[FBSDKAccessToken currentAccessToken]appID],
[[FBSDKAccessToken currentAccessToken]userID],
[[FBSDKAccessToken currentAccessToken]refreshDate],
[[FBSDKAccessToken currentAccessToken]tokenString]
);

//Get some profile data
FBSDKGraphRequest *requestMe = [[FBSDKGraphRequest alloc]initWithGraphPath:@”me” parameters:@{@”fields”: @”email, first_name, last_name”}];
FBSDKGraphRequestConnection *connection = [[FBSDKGraphRequestConnection alloc] init];
[connection addRequest:requestMe completionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if(result) {
NSString *sUserID, *sEmail, *sFirstName, *sLastName;
if ([result objectForKey:@”email”]) {
sEmail = [result objectForKey:@”email”];
}
if ([result objectForKey:@”first_name”]) {
sFirstName = [result objectForKey:@”first_name”];
}
if ([result objectForKey:@”last_name”]) {
sLastName = [result objectForKey:@”last_name”];
}
if ([result objectForKey:@”id”]) {
sUserID = [result objectForKey:@”id”];
}

NSLog(@”Customer details:[%@][%@][%@][%@]”, sUserID, sFirstName, sLastName, sEmail);

//Facebook account was authenticated OK, do whatever you need
}];
[connection start];
}
}];
}

 

Posted in iOS development | Leave a comment

Google SignIn iOS practice log

Google Sign-in for iOS

1.Download GoogleSignIn SDK
https://developers.google.com/identity/sign-in/ios/sdk/
There are two ways to get the SDK, CocoaPod or direct download,
Personally I preferred the download way.
0.Download SDK
Follow the official document procedure
https://developers.google.com/identity/sign-in/ios/start

2.Get configuration file
https://developers.google.com/mobile/add?platform=ios&cntapi=signin&cntapp=Default%20Demo%20App&cntpkg=com.google.samples.quickstart.SignInExample&cnturl=https:%2F%2Fdevelopers.google.com%2Fidentity%2Fsign-in%2Fios%2Fstart%3Fconfigured%3Dtrue&cntlbl=Continue%20with%20Try%20Sign-In

2.EnableSignin

 

3.Copy to project directory first then “pull” into xcode project
Basically just pull the configuration file into the xcode project  and it is OK.
But you will gonna thank me for this lousy procedure when there are multiple configuration files in one xcode project.
3.Download plist
4.Configure xcode project-level parameters
https://developers.google.com/identity/sign-in/ios/sign-in?configured=true

Put REVERSED_CLIENT_ID into Project -> Target -> Info -> URL Types
Put bundle id into Project -> Target -> Info -> URL Types

4.URLTypes

 

5.Modify source code
There will be only one file to be modified – AppDelegate

The most important statement is to set [GIDSignIn sharedInstance].clientID = CLIENT_ID(in configuration)

 

 

 

 

Posted in iOS development | Leave a comment

How to fix – There was an internal API error

There was an internal API error

XCode build app 至 iPhone 時出現此錯誤

解決方法:

Target->Build Setting->Product Name

Remove any “weird” characters and keep there only English characters.

Posted in iOS development | 4 Comments

簡單學日語 2.0 上架了

簡單學日語 2.0 上架了

https://itunes.apple.com/tw/app/jian-dan-xue-ri-yu/id907920405?mt=8

iOS 的 app 真麻煩

iOS 的版本只要一升級

就得回頭 revise 所有的 app

要不然就會莫名其妙的閃退

日前心血來潮看了一下這個 app

才發現早就閃退到不行

只好趕快改一改再上架更新

Posted in 簡單學日語 | 2 Comments

Unable to create description in descriptionForLayoutAttribute_layoutItem_coefficient. Something is nil

Unable to create description in descriptionForLayoutAttribute_layoutItem_coefficient. Something is nil

 

Symptom: Normal but crash in iOS 7 device.

Possible reason : Use some “Baseline” constraints (Only supported after iOS 8) in storyboard.

Solution : Remove any “Baseline” constraints of that page crashed in storyboard.

Posted in iOS development | Leave a comment

XCode SVN is not under version control

That is the keyword I Googled for solution and no luck.

I’m too old to learn new source control mechanism like Git so I stuck on SVN with XCode.

It works perfect usually but sometimes it show “xxx is not under version control”.

For me, the reason is some special character in file name , in my case , the @ character.

I googled and tried to fixed this issue but no luck.

And today, finally, I solved this issue with one single step, simple and straight.

Open “Terminal” application, go to the project folder and keyin this

svn commit -m “Happy SVN”

And you’ll see all the files (including file name with @ character) are committed successfully.

I don’t know why the commit won’t succeed in XCode, but I’m happy that it works in command line mode.

 

Update on 2016/03/02:

Sometimes you have to make those @xx.png files the Add status (with A in the right) in Xcode first before you do the command-line svn commit.

Posted in iOS development | Tagged , , , , , , | Leave a comment

Custom URL schemes practice

Let’s define something in this scenario :

1.Receiver app – to be invoked via custom URL

2.Sender app – who wants to invoke the app

3.Custom URL scheme – define as “happygo”

 

 

For Receiver app, here’s what to do:

1.Define the url scheme in Project/Targets/Info/URL Types as follow

螢幕快照 2016-02-04 下午12.20.51

2.AppDelegate.m – Two methods to be implemented.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
 return YES;    //must return YES
 }
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
 //Check if the scheme was valid
 if ([[url scheme] isEqualToString:@"happygo"]) {
 NSString *query = [url query];
 NSArray *queryComponents = [query componentsSeparatedByString:@"&"];

 for (int i=0; i<[queryComponents count]; i++) {
 NSArray *oneParam = [[queryComponents objectAtIndex:i] componentsSeparatedByString:@"="];
 NSString *sValue = @"";
 NSString *sKey = [oneParam objectAtIndex:0];
 if (oneParam.count==2) {
 sValue = [oneParam objectAtIndex:1];
 }
 }
 //Here is what you want to do, write here.
 return TRUE;   //return TRUE because of valid scheme
 }
 return FALSE;   //invalid scheme, skip process
 }

 

 

For Sender app, here’s what to do :

1.Add the following to info.plist

<key>LSApplicationQueriesSchemes</key>
 <array>
 <string>happygo</string>
 </array>

2.Invoke the receiver app via URL form, sample source code as follow

NSString *sURL = [NSString stringWithFormat:@"happygo://www.domain.com?name=Good&phone=123123"];
 NSURL *myURL = [NSURL URLWithString:sURL];

 if ([[UIApplication sharedApplication] canOpenURL:myURL]) {
 [[UIApplication sharedApplication] openURL:myURL];
 } else {
 NSLog(@"--bad url--");
 }

Actually, you can even invoke the app via Safari Browser.

Just input the URL in Safari, press GO, and the receiver app will be invoked.

Posted in iOS development | Leave a comment

iOS Watchkit Development – paired device unavailable for development

I had this problem twice, I googled the same article to do the same actions to fix.

Here I wrote down to remember myself.

Error : “paired device unavailable for development” showed in XCode when new to Apple Watch

Fix steps :

  1. Unpair my watch
  2. Reboot both iPhone and apple watch
  3. Pair them again, and setup my watch as a new one
  4. Plug (unplug first) iPhone to Mac
  5. On apple watch, say Trust the computer when it asks
  6. Unplug and plug again
  7. Close and open XCode
  8. Open the project and wait a few seconds

Good luck.

Posted in iOS development | 3 Comments

Icon only UITabbar, no title at all.

1.Clear the title attribute to empty.

2.Set the Image Insect attribute of the Tabbar item as follow

tabbarinsect

And you’re good to go.

Happy Tabbaring…

Posted in iOS development | Leave a comment