Google OAuth for iOS - google-oauth

I'm developing an iOS app, where I would like to have both Facebook and Google OAuth as login. I'm working on Facebook OAuth, but I don't have any idea about the Google OAuth. Any help on this would be very helpful.

Important : Google + API sign in and share do without leaving app. that is key element in avoiding app rejection.
Step 1 : Add Google+ client ID
Step 2 : Google+ Sign In delegates
-(void)finishedWithAuth: (GTMOAuth2Authentication *)auth
error: (NSError *) error
{
}
Step 3 : In App delegate
- (BOOL) application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
if ([[url scheme] isEqualToString:FBTOKEN]) {
return [FBSession.activeSession handleOpenURL:url];
return [FBAppCall handleOpenURL:url
sourceApplication:sourceApplication
withSession:FBSession.activeSession];
}
else {
[GPPURLHandler handleURL:url sourceApplication:sourceApplication annotation:annotation];
}
return YES;
}

Related

linking.addEventListener is not working for ios when application is in foreground

For ios, if the push notification is received when the application is in foreground, when user clicks on push notification, Linking.addEventListener is not getting executed.
The requirement is to move the user to a specific page once the push notification is clicked.
If the the application is not running or application is open but in background. In both this cases the Linking.addEventListener works as expected.
**Code from appdelegate.m
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
return [RCTLinkingManager application:application openURL:url
sourceApplication:sourceApplication annotation:annotation];
}
// Only if your app is using [Universal Links](https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/AppSearch/UniversalLinks.html).
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler
{
return [RCTLinkingManager application:application
continueUserActivity:userActivity
restorationHandler:restorationHandler];
}
react-native code to handle deep linking
if (Platform.OS === 'android') {
Linking.getInitialURL().then(url => {
const { navigate } = this.props.navigation;
let c = url.replace("abcdapp://abcd/", "")
navigate(c)
});
} else {
Linking.addEventListener('url', this.handleOpenURL);
}
Linking.addEventListener('url', this.handleOpenURL);

Linking.addEventListener not working in react native

I have successfully implemented a universal link that opens up a specific page in my app (if the app is turned off). The problem is that if the app is running in the background, the eventListener is not being called. Here is the code:
import {Linking} from 'react-native';
export default class App extends React.Component {
async componentDidMount(){
Linking.addEventListener('url', this._handleOpenURL);
let url = await Linking.getInitialURL();
if (url) {
console.log('MOUNT GET INIT URL','initial url ' + url);
}
}
_handleOpenURL = (event) => {
console.log("in _handleOpenURL", event.url)
}
}
MOUNT GET INIT URL is successfully logged to the console. in _handleOpenURL is never logged. It seems other people on the internet have had this problem but no one has answered it. Does anyone know what to do?
Add this just before the last #end in appdelegate.m:
// iOS 9.x or newer
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
return [RCTLinkingManager application:application openURL:url options:options];
}
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler
{
return [RCTLinkingManager application:application
continueUserActivity:userActivity
restorationHandler:restorationHandler];
}

React Native, iOS, Google Signin will redirect to google.com if you install FBSDK as well

If you install Google Signin, https://github.com/devfd/react-native-google-signin , then you follow setup instructions from Google. At this step, you can do the signin well.
After that, you install FBSDK as well, https://github.com/facebook/react-native-fbsdk , then you follow setup instructions from Facebook. At this step, you will be redirected to google.com .
open your AppDelegate.m, existing code:
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
BOOL handled = [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:options[UIApplicationOpenURLOptionsAnnotationKey]
];
// Add any custom logic here.
return handled;
}
modify it to:
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
BOOL handled = [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:options[UIApplicationOpenURLOptionsAnnotationKey]
]
|| [RNGoogleSignin application:application
openURL:url
sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:options[UIApplicationOpenURLOptionsAnnotationKey]
];
// Add any custom logic here.
return handled;
}

Silent notification

Although I receive a silent notification (content-available=1) in my app, a pop up message appear all the times which should not happen. I use the OneSignal service. Could anybody assist?
Methods executed are as follows:
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Many thanks
The full code shown below:
import "AppDelegate.h"
#interface AppDelegate ()
#end
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// OneSignal Push Notifications
self.oneSignal = [[OneSignal alloc] initWithLaunchOptions:launchOptions
appId:#"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
handleNotification:nil];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
// 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 inactive state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
// system push notification registration success callback, delegate to pushManager
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken {
NSLog(#"My token is: %#", deviceToken);
}
// system push notification registration error callback, delegate to pushManager
- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error {
NSLog(#"Failed to get token, error: %#", error);
}
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
NSLog(#"PUSH NOTIFICATION %#",userInfo);
if([userInfo[#"aps"][#"content-available"] intValue] == 1) {
NSLog(#"SILENT PUSH NOTIFICATION");
if (completionHandler) {
completionHandler(UIBackgroundFetchResultNoData);
}
} else {
NSLog(#" GENERAL PUSH NOTIFICATION ");
if (completionHandler) {
completionHandler(UIBackgroundFetchResultNoData);
}
}
}
- (void)application:(UIApplication *) application
handleActionWithIdentifier: (NSString *) identifier
forRemoteNotification: (NSDictionary *) additionalData
completionHandler: (void (^)()) completionHandler {
if (completionHandler) {
completionHandler(UIBackgroundFetchResultNoData);
}
}
#end
notification payload looks like this
{
"aps": {
"badge": 10,
"alert": "Hello world!",
"sound": "Default"
}
}
if you not want msg banner or alert show then not add alert key in your payload
{
"aps": {
"badge": 10,
"sound": "Default"
}
}
hope its work for you.
You can make unable and disable your notification by this code .
may be help you
if ([[UIApplication sharedApplication]respondsToSelector:#selector(isRegisteredForRemoteNotifications)])
{
// For iOS 8 and above
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else
{
// For iOS < 8
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
}

Facebook openActiveSessionWithReadPermission reach completion too fast with status fail

[FBSession openActiveSessionWithReadPermissions:nil
allowLoginUI:YES
completionHandler:
^(FBSession *session,
FBSessionState state, NSError *error) {
[self sessionStateChanged:session state:state error:error];
}];
Well, after a while an alert show us saying that my application tries to access facebook and ask whether it's allowed or not.
However, that alert shows up AFTER completion handler is reached.
State is already FBSessionStateClosedLoginFailed by that time.
What should I do? Works fine in simulator.
Actually scrumptious sample in face book also fail on my iPhone. But I have facebook apps installed and logged in.
Facebook Login checklist:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [FBSession.activeSession handleOpenURL:url];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
// We need to properly handle activation of the application with regards to SSO
// (e.g., returning from iOS 6.0 authorization dialog or from fast app switching).
[FBSession.activeSession handleDidBecomeActive];
}
- (void)applicationWillTerminate:(UIApplication *)application {
// if the app is going away, we close the session object; this is a good idea because
// things may be hanging off the session, that need releasing (completion block, etc.) and
// other components in the app may be awaiting close notification in order to do cleanup
[FBSession.activeSession close];
}
In my sessionStateChanged: I am doing this
switch ( state ) {
case FBSessionStateOpen:
[[Facebook _instance] fbDialogLogin:session.accessToken expirationDate:session.expirationDate];
break;
case FBSessionStateClosed:
[FBSession.activeSession closeAndClearTokenInformation];
break;
case FBSessionStateClosedLoginFailed:
break;
default:
NSLog(#"FBSessionStateUnknown: %d", state);
break;
}
And dont forget to make sure that your FacebookAppID and BundleID is the same as the one you create in Facebook Developer Dashboard!