This commit fixes multiple issues identified by PR commentors.
1.It updates the header readme of all files to the correct liscense. 2.APNSToken has been changed from a singleton pattern to directly return the APNSToken from a a class-wide message implemenation method. 3. Removed all references to Project Rome. 4. Removing adaptive cards as it is no longer needed. 5. Fixing MSA scopes. 6. Deduping code between MSA and AAD logins. 7. Updating Secrets.h to have the required paramaters in the new graph notifications client.
This commit is contained in:
Родитель
f80d95e388
Коммит
f3c3c53e21
|
@ -1,8 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>IDEDidComputeMac32BitWarning</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
Двоичные данные
GraphNotifications/GraphNotificationsSample.xcworkspace/xcuserdata/adcrabtr.xcuserdatad/UserInterfaceState.xcuserstate
сгенерированный
Двоичные данные
GraphNotifications/GraphNotificationsSample.xcworkspace/xcuserdata/adcrabtr.xcuserdatad/UserInterfaceState.xcuserstate
сгенерированный
Двоичный файл не отображается.
|
@ -1,18 +0,0 @@
|
|||
//
|
||||
// APNSToken.h
|
||||
// GraphNotificationsSample
|
||||
//
|
||||
// Created by Adam Crabtree on 12/27/19.
|
||||
// Copyright © 2019 Microsoft. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef APNSToken_h
|
||||
#define APNSToken_h
|
||||
|
||||
@interface APNSToken : NSObject
|
||||
+(id)accessToken;
|
||||
-(void)setAccessToken:(NSString*)token;
|
||||
-(NSString*)getAccessToken;
|
||||
@end
|
||||
|
||||
#endif /* APNSToken_h */
|
|
@ -1,34 +0,0 @@
|
|||
//
|
||||
// APNSToken.m
|
||||
// GraphNotificationsSample
|
||||
//
|
||||
// Created by Adam Crabtree on 12/27/19.
|
||||
// Copyright © 2019 Microsoft. All rights reserved.
|
||||
//
|
||||
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "APNSToken.h"
|
||||
@implementation APNSToken
|
||||
static APNSToken* _APNSToken;
|
||||
static NSString* apnsToken;
|
||||
+(id)accessToken{
|
||||
@synchronized ([APNSToken class]) {
|
||||
if(!_APNSToken)
|
||||
{
|
||||
_APNSToken = [[self alloc]init];
|
||||
}
|
||||
return _APNSToken;
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
-(void)setAccessToken:(NSString*)token
|
||||
{
|
||||
apnsToken = token;
|
||||
}
|
||||
-(NSString*)getAccessToken
|
||||
{
|
||||
return apnsToken;
|
||||
}
|
||||
|
||||
@end
|
|
@ -1,19 +0,0 @@
|
|||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
// These come from the converged app registration portal at apps.dev.microsoft.com
|
||||
// MSA_CLIENT_ID: Id of this app's registration in the MSA portal
|
||||
// AAD_CLIENT_ID: Id of this app's registration in the Azure portal
|
||||
// AAD_REDIRECT_URI: A Uri that this app is registered with in the Azure portal.
|
||||
// AAD is supposed to use this Uri to call the app back after login (currently not true, external requirement)
|
||||
// And this app is supposed to be able to handle this Uri (currently not true)
|
||||
// APP_HOST_NAME Cross-device domain of this app's registration
|
||||
static NSString* const MSA_CLIENT_ID = @"<<MSA client ID goes here>>";
|
||||
static NSString* const AAD_CLIENT_ID = @"<<AAD client ID goes here>>";
|
||||
static NSString* const AAD_REDIRECT_URI = @"<<AAD redirect URI goes here>>";
|
||||
static NSString* const APP_HOST_NAME = @"<<App cross-device domain goes here>>";
|
|
@ -1,12 +0,0 @@
|
|||
# GraphNotifications sample for iOS
|
||||
|
||||
Microsoft Graph notifications is built on the top of UserNotifications feature from [Project Rome](https://developer.microsoft.com/en-us/windows/project-rome) which is the Microsoft's cross-device experiences platform. See the [UserNotifications API reference](https://docs.microsoft.com/en-us/windows/project-rome/notifications/) for how-to guides and API docs that will help you get started integrating UserNotifications feature into your app.
|
||||
|
||||
Here you can find the sample app that showcase [Microsoft Graph notifications](https://docs.microsoft.com/en-us/graph/notifications-concept-overview) features on iOS. You will need an iOS app development IDE and iOS device or emulator to use this sample.
|
||||
|
||||
Steps to build and run the sample
|
||||
1. git clone https://github.com/Microsoft/project-rome.git
|
||||
2. cd ./project-rome/iOS/samples/GraphNotifications/
|
||||
3. pod install (Note, you might have to do 'pod repo update' and 'pod update' if you run into build issues).
|
||||
4. Open the generated GraphNotifications.xcworkspace in Xcode to build and run the sample.
|
||||
5. For the sample to work properly, you need to update the values in 'Secrets.h' file. The values can be obtained by registering your app for authentication and push notifications. See [How-to guide for iOS](https://docs.microsoft.com/en-us/windows/project-rome/notifications/how-to-guide-for-ios) for complete guidance.
|
|
@ -0,0 +1,68 @@
|
|||
# Xcode
|
||||
#
|
||||
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
|
||||
|
||||
## User settings
|
||||
xcuserdata/
|
||||
|
||||
## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
|
||||
*.xcscmblueprint
|
||||
*.xccheckout
|
||||
|
||||
## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
|
||||
build/
|
||||
DerivedData/
|
||||
*.moved-aside
|
||||
*.pbxuser
|
||||
!default.pbxuser
|
||||
*.mode1v3
|
||||
!default.mode1v3
|
||||
*.mode2v3
|
||||
!default.mode2v3
|
||||
*.perspectivev3
|
||||
!default.perspectivev3
|
||||
|
||||
## Obj-C/Swift specific
|
||||
*.hmap
|
||||
|
||||
## App packaging
|
||||
*.ipa
|
||||
*.dSYM.zip
|
||||
*.dSYM
|
||||
|
||||
# CocoaPods
|
||||
#
|
||||
# We recommend against adding the Pods directory to your .gitignore. However
|
||||
# you should judge for yourself, the pros and cons are mentioned at:
|
||||
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
||||
#
|
||||
Pods/
|
||||
#
|
||||
# Add this line if you want to avoid checking in source code from the Xcode workspace
|
||||
*.xcworkspace
|
||||
|
||||
# Carthage
|
||||
#
|
||||
# Add this line if you want to avoid checking in source code from Carthage dependencies.
|
||||
# Carthage/Checkouts
|
||||
|
||||
Carthage/Build/
|
||||
|
||||
# fastlane
|
||||
#
|
||||
# It is recommended to not store the screenshots in the git repo.
|
||||
# Instead, use fastlane to re-generate the screenshots whenever they are needed.
|
||||
# For more information about the recommended setup visit:
|
||||
# https://docs.fastlane.tools/best-practices/source-control/#source-control
|
||||
|
||||
fastlane/report.xml
|
||||
fastlane/Preview.html
|
||||
fastlane/screenshots/**/*.png
|
||||
fastlane/test_output
|
||||
|
||||
# Code Injection
|
||||
#
|
||||
# After new code Injection tools there's a generated folder /iOSInjectionProject
|
||||
# https://github.com/johnno1962/injectionforxcode
|
||||
|
||||
iOSInjectionProject/
|
|
@ -17,8 +17,7 @@
|
|||
00823375212F114B0055F6E4 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 00823374212F114B0055F6E4 /* main.m */; };
|
||||
00D6D060213720E5008E5E33 /* NotificationsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D6D05F213720E5008E5E33 /* NotificationsViewController.m */; };
|
||||
232485673C6C2171E330D4C6 /* Pods_GraphNotificationsSample.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 11DF974EC8752FA5D016C967 /* Pods_GraphNotificationsSample.framework */; };
|
||||
AE59AE8023B539E8000A04E7 /* UserNotificationApi.m in Sources */ = {isa = PBXBuildFile; fileRef = AE59AE7F23B539E8000A04E7 /* UserNotificationApi.m */; };
|
||||
AE59AE8223B69590000A04E7 /* APNSToken.m in Sources */ = {isa = PBXBuildFile; fileRef = AE59AE8123B69590000A04E7 /* APNSToken.m */; };
|
||||
AE59AE8223B69590000A04E7 /* GlobalApnsToken.m in Sources */ = {isa = PBXBuildFile; fileRef = AE59AE8123B69590000A04E7 /* GlobalApnsToken.m */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
|
@ -43,10 +42,8 @@
|
|||
63E3FBAFA254E6B80A8DA76E /* Pods-GraphNotifications.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-GraphNotifications.release.xcconfig"; path = "Pods/Target Support Files/Pods-GraphNotifications/Pods-GraphNotifications.release.xcconfig"; sourceTree = "<group>"; };
|
||||
913EB4AA217E75C700A78C79 /* Secrets.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Secrets.h; sourceTree = "<group>"; };
|
||||
9B6312F300B55978A0074729 /* libPods-GraphNotifications.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-GraphNotifications.a"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
AE59AE7E23B539D9000A04E7 /* UserNotificationApi.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UserNotificationApi.h; sourceTree = "<group>"; };
|
||||
AE59AE7F23B539E8000A04E7 /* UserNotificationApi.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = UserNotificationApi.m; sourceTree = "<group>"; };
|
||||
AE59AE8123B69590000A04E7 /* APNSToken.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = APNSToken.m; sourceTree = "<group>"; };
|
||||
AE59AE8323B6959D000A04E7 /* APNSToken.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = APNSToken.h; sourceTree = "<group>"; };
|
||||
AE59AE8123B69590000A04E7 /* GlobalApnsToken.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GlobalApnsToken.m; sourceTree = "<group>"; };
|
||||
AE59AE8323B6959D000A04E7 /* GlobalApnsToken.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GlobalApnsToken.h; sourceTree = "<group>"; };
|
||||
D94FF25B740D15AF01A2530D /* Pods-GraphNotificationsSample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-GraphNotificationsSample.release.xcconfig"; path = "Pods/Target Support Files/Pods-GraphNotificationsSample/Pods-GraphNotificationsSample.release.xcconfig"; sourceTree = "<group>"; };
|
||||
E9737A60E31BEADDB7BDC7BE /* Pods-GraphNotificationsSample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-GraphNotificationsSample.debug.xcconfig"; path = "Pods/Target Support Files/Pods-GraphNotificationsSample/Pods-GraphNotificationsSample.debug.xcconfig"; sourceTree = "<group>"; };
|
||||
FFB1B176FF8985E5AD4B88D1 /* Pods-GraphNotifications.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-GraphNotifications.debug.xcconfig"; path = "Pods/Target Support Files/Pods-GraphNotifications/Pods-GraphNotifications.debug.xcconfig"; sourceTree = "<group>"; };
|
||||
|
@ -102,10 +99,8 @@
|
|||
00D6D05E21372041008E5E33 /* NotificationsViewController.h */,
|
||||
00D6D05F213720E5008E5E33 /* NotificationsViewController.m */,
|
||||
913EB4AA217E75C700A78C79 /* Secrets.h */,
|
||||
AE59AE7E23B539D9000A04E7 /* UserNotificationApi.h */,
|
||||
AE59AE7F23B539E8000A04E7 /* UserNotificationApi.m */,
|
||||
AE59AE8123B69590000A04E7 /* APNSToken.m */,
|
||||
AE59AE8323B6959D000A04E7 /* APNSToken.h */,
|
||||
AE59AE8123B69590000A04E7 /* GlobalApnsToken.m */,
|
||||
AE59AE8323B6959D000A04E7 /* GlobalApnsToken.h */,
|
||||
);
|
||||
path = GraphNotificationsSample;
|
||||
sourceTree = "<group>";
|
||||
|
@ -215,24 +210,24 @@
|
|||
);
|
||||
inputPaths = (
|
||||
"${PODS_ROOT}/Target Support Files/Pods-GraphNotificationsSample/Pods-GraphNotificationsSample-frameworks.sh",
|
||||
"${BUILT_PRODUCTS_DIR}/ADAL/ADAL.framework",
|
||||
"${BUILT_PRODUCTS_DIR}/AFNetworking/AFNetworking.framework",
|
||||
"${PODS_ROOT}/AdaptiveCards/AdaptiveCards.framework",
|
||||
"${PODS_ROOT}/AdaptiveCards/AdaptiveCards.framework.dSYM",
|
||||
"${PODS_ROOT}/GraphNotificationsLibrary/GraphNotificationsLibrary.framework",
|
||||
"${BUILT_PRODUCTS_DIR}/ISO8601/ISO8601.framework",
|
||||
"${BUILT_PRODUCTS_DIR}/JSONModel/JSONModel.framework",
|
||||
"${BUILT_PRODUCTS_DIR}/MSAL/MSAL.framework",
|
||||
"${BUILT_PRODUCTS_DIR}/PromiseKit/PromiseKit.framework",
|
||||
);
|
||||
name = "[CP] Embed Pods Frameworks";
|
||||
outputPaths = (
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ADAL.framework",
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/AFNetworking.framework",
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/AdaptiveCards.framework",
|
||||
"${DWARF_DSYM_FOLDER_PATH}/AdaptiveCards.framework.dSYM",
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GraphNotificationsLibrary.framework",
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ISO8601.framework",
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/JSONModel.framework",
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MSAL.framework",
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PromiseKit.framework",
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
|
@ -266,10 +261,9 @@
|
|||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
00823375212F114B0055F6E4 /* main.m in Sources */,
|
||||
AE59AE8223B69590000A04E7 /* APNSToken.m in Sources */,
|
||||
AE59AE8223B69590000A04E7 /* GlobalApnsToken.m in Sources */,
|
||||
00823364212F114B0055F6E4 /* RootViewController.m in Sources */,
|
||||
003421A921347622007FC970 /* NotificationsManager.m in Sources */,
|
||||
AE59AE8023B539E8000A04E7 /* UserNotificationApi.m in Sources */,
|
||||
00D6D060213720E5008E5E33 /* NotificationsViewController.m in Sources */,
|
||||
00823367212F114B0055F6E4 /* LoginViewController.m in Sources */,
|
||||
00823361212F114B0055F6E4 /* AppDelegate.m in Sources */,
|
|
@ -5,7 +5,7 @@
|
|||
#import "AppDelegate.h"
|
||||
#import <GraphNotificationsLibrary/UserNotificationApi.h>
|
||||
#import <GraphNotificationsLibrary/UserNotification.h>
|
||||
#import "APNSToken.h"
|
||||
#import "GlobalApnsToken.h"
|
||||
@implementation AppDelegate {
|
||||
|
||||
}
|
||||
|
@ -62,7 +62,7 @@
|
|||
NSLog(@"GraphNotificationsSample APNs token: %@", deviceTokenStr);
|
||||
|
||||
@try {
|
||||
[[APNSToken accessToken] setAccessToken:deviceTokenStr];
|
||||
[GlobalApnsToken setGlobalApnsToken:deviceTokenStr];
|
||||
} @catch (NSException* exception) {
|
||||
NSLog(@"Failed to update notification registration with exception %@", exception);
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
|
||||
|
||||
#ifndef APNSToken_h
|
||||
#define APNSToken_h
|
||||
|
||||
@interface GlobalApnsToken: NSObject
|
||||
+(NSString *) apnsDeviceToken;
|
||||
+(void) setGlobalApnsToken:(NSString*)apnsToken;
|
||||
@end
|
||||
|
||||
#endif /* APNSToken_h */
|
|
@ -0,0 +1,25 @@
|
|||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
|
||||
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "GlobalApnsToken.h"
|
||||
@implementation GlobalApnsToken
|
||||
static NSString *g_apnsToken = 0;
|
||||
+(NSString *) apnsDeviceToken {
|
||||
@synchronized ([GlobalApnsToken class]) {
|
||||
if (!g_apnsToken)
|
||||
{
|
||||
g_apnsToken = [NSString string];
|
||||
}
|
||||
return g_apnsToken;
|
||||
}
|
||||
}
|
||||
+(void) setGlobalApnsToken:(NSString*)apnsToken
|
||||
{
|
||||
g_apnsToken = apnsToken;
|
||||
}
|
||||
@end
|
||||
|
|
@ -28,23 +28,13 @@ typedef NS_ENUM(NSInteger, LoginState) {
|
|||
|
||||
if (state == SIGNED_OUT) {
|
||||
[self _setStatusText:@"Signing in MSA..."];
|
||||
NSError* msalError = [[NSError alloc] init];
|
||||
MSALAuthority* authority = [MSALAuthority authorityWithURL:[NSURL URLWithString:@"https://login.microsoftonline.com/consumers/"] error:&msalError];
|
||||
MSALPublicClientApplicationConfig *config = [[MSALPublicClientApplicationConfig alloc] initWithClientId:MSA_CLIENT_ID];
|
||||
NSArray<NSString *> *scopes = @[@"https://activity.microsoft.com/UserActivity.ReadWrite.CreatedByApp", @"https://activity.microsoft.com/Notifications.ReadWrite.CreatedByApp"];
|
||||
MSALWebviewParameters* params = [[MSALWebviewParameters alloc] initWithParentViewController:self];
|
||||
MSALPublicClientApplication *application = [[MSALPublicClientApplication alloc] initWithConfiguration:config error:&msalError];
|
||||
MSALInteractiveTokenParameters *interactiveParams = [[MSALInteractiveTokenParameters alloc] initWithScopes:scopes webviewParameters:params];
|
||||
interactiveParams.authority = authority;
|
||||
interactiveParams.promptType = MSALPromptTypeSelectAccount;
|
||||
|
||||
[application acquireTokenWithParameters:interactiveParams completionBlock:^(MSALResult *result, NSError *error) {
|
||||
[self loginInternal:MSA finishBlock:^(NSError *error, NSString* accessToken) {
|
||||
if (!error)
|
||||
{
|
||||
// You'll want to get the account identifier to retrieve and reuse the account
|
||||
// for later acquireToken calls
|
||||
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
|
||||
appDelegate.manager = [appDelegate.manager initWithAccount:result.accessToken];
|
||||
appDelegate.manager = [appDelegate.manager initWithAccount:accessToken];
|
||||
if(appDelegate.manager)
|
||||
{
|
||||
[self _setButtonTextAndVisibilityForState:MSA];
|
||||
|
@ -66,6 +56,43 @@ typedef NS_ENUM(NSInteger, LoginState) {
|
|||
}
|
||||
}
|
||||
|
||||
-(void)loginInternal:(LoginState)accountToLogin finishBlock:(void (^)(NSError* error, NSString* accessToken))finishBlock
|
||||
{
|
||||
NSError* msalError = [[NSError alloc] init];
|
||||
MSALAuthority* authority;
|
||||
MSALPublicClientApplicationConfig *config;
|
||||
NSArray<NSString *> *scopes;
|
||||
if(accountToLogin==AAD)
|
||||
{
|
||||
authority = [MSALAuthority authorityWithURL:[NSURL URLWithString:@"https://login.microsoftonline.com/common/oauth2"] error:&msalError];
|
||||
config = [[MSALPublicClientApplicationConfig alloc] initWithClientId:APPLICATION_CLIENT_ID];
|
||||
scopes = @[@"https://activity.microsoft.com/UserActivity.ReadWrite.CreatedByApp", @"https://activity.microsoft.com/Notifications.ReadWrite.CreatedByApp"];
|
||||
}
|
||||
else if(accountToLogin==MSA)
|
||||
{
|
||||
authority = [MSALAuthority authorityWithURL:[NSURL URLWithString:@"https://login.microsoftonline.com/consumers/"] error:&msalError];
|
||||
config = [[MSALPublicClientApplicationConfig alloc] initWithClientId:APPLICATION_CLIENT_ID];
|
||||
scopes = @[@"https://activity.windows.com/UserActivity.ReadWrite.CreatedByApp", @"https://activity.windows.com/Notifications.ReadWrite.CreatedByApp"];
|
||||
}
|
||||
|
||||
MSALWebviewParameters* params = [[MSALWebviewParameters alloc] initWithParentViewController:self];
|
||||
MSALPublicClientApplication *application = [[MSALPublicClientApplication alloc] initWithConfiguration:config error:&msalError];
|
||||
MSALInteractiveTokenParameters *interactiveParams = [[MSALInteractiveTokenParameters alloc] initWithScopes:scopes webviewParameters:params];
|
||||
interactiveParams.authority = authority;
|
||||
interactiveParams.promptType = MSALPromptTypeSelectAccount;
|
||||
[application acquireTokenWithParameters:interactiveParams completionBlock:^(MSALResult *result, NSError *error) {
|
||||
if (!error)
|
||||
{
|
||||
finishBlock(nil, result.accessToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
finishBlock(error, nil);
|
||||
}
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
- (IBAction)loginAAD {
|
||||
LoginState state = [self _getState];
|
||||
|
||||
|
@ -73,7 +100,7 @@ typedef NS_ENUM(NSInteger, LoginState) {
|
|||
[self _setStatusText:@"Signing in AAD..."];
|
||||
NSError* msalError = [[NSError alloc] init];
|
||||
MSALAuthority* authority = [MSALAuthority authorityWithURL:[NSURL URLWithString:@"https://login.microsoftonline.com/common/oauth2"] error:&msalError];
|
||||
MSALPublicClientApplicationConfig *config = [[MSALPublicClientApplicationConfig alloc] initWithClientId:AAD_CLIENT_ID];
|
||||
MSALPublicClientApplicationConfig *config = [[MSALPublicClientApplicationConfig alloc] initWithClientId:APPLICATION_CLIENT_ID];
|
||||
NSArray<NSString *> *scopes = @[@"https://activity.microsoft.com/UserActivity.ReadWrite.CreatedByApp", @"https://activity.microsoft.com/Notifications.ReadWrite.CreatedByApp"];
|
||||
MSALWebviewParameters* params = [[MSALWebviewParameters alloc] initWithParentViewController:self];
|
||||
MSALPublicClientApplication *application = [[MSALPublicClientApplication alloc] initWithConfiguration:config error:&msalError];
|
|
@ -5,7 +5,7 @@
|
|||
#import "NotificationsManager.h"
|
||||
#import <UserNotifications/UserNotifications.h>
|
||||
#import "Secrets.h"
|
||||
#import "APNSToken.h"
|
||||
#import "GlobalApnsToken.h"
|
||||
|
||||
@implementation NotificationsManager {
|
||||
NSMutableArray<UserNotification*>* _notifications;
|
||||
|
@ -99,7 +99,7 @@
|
|||
_listenerMap = [NSMutableDictionary dictionary];
|
||||
_userNotificationApi = [[UserNotificationApi alloc] init];
|
||||
[_userNotificationApi setOAuthAccessToken:accountId];
|
||||
[_userNotificationApi subscribeToUserNotificationsAsync:[[APNSToken accessToken] getAccessToken] appPackageNameForPushPlatform:APP_HOST_NAME appDisplayNameForUnsAnalytics:@"GraphNotificationsSample" completionHandler:^(UserNotificationSubscriptionResult * result) {
|
||||
[_userNotificationApi subscribeToUserNotificationsAsync:[GlobalApnsToken apnsDeviceToken] appPackageNameForPushPlatform:APP_HOST_NAME appDisplayNameForUnsAnalytics:@"GraphNotificationsSample" completionHandler:^(UserNotificationSubscriptionResult * result) {
|
||||
if(result.getStatus==SUCCEEDED)
|
||||
{
|
||||
NSLog(@"Registered for remote notifications successfully");
|
|
@ -0,0 +1,13 @@
|
|||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
// These come from the converged app registration portal at https://ms.portal.azure.com/#home and onboarding portal https://partner.microsoft.com/en-us/dashboard/mpn/overview
|
||||
// APPLICATION_CLIENT_ID: Id of this app's registration in the Azure portal
|
||||
// APP_HOST_NAME Cross-device domain of this app's registration
|
||||
static NSString* const APPLICATION_CLIENT_ID = @"<<AAD client ID goes here>>";
|
||||
static NSString* const APP_HOST_NAME = @"<<App cross-device domain goes here>>";
|
|
@ -6,13 +6,10 @@ target 'GraphNotificationsSample' do
|
|||
# Uncomment the next line if you're using Swift or would like to use dynamic frameworks
|
||||
use_frameworks!
|
||||
|
||||
# This is the main ConnectedDevices SDK. It includes all the functionality needed for RemoteSystems and UserData scenarios
|
||||
# This is the main Graph Notifications SDK. It includes all the functionality needed for Receiving and interacting with notifications
|
||||
pod 'GraphNotificationsLibrary', '~>0.0.6'
|
||||
pod 'MSAL'
|
||||
# Because the ConnectedDevices platform involves many asynchronous calls (getting user tokens, sending messages to remote apps etc.)
|
||||
# it is helpful to have a strategy to sequence all of the completions in an organized manner. https://blog.hellojs.org/asynchronous-javascript-from-callback-hell-to-async-and-await-9b9ceb63c8e8
|
||||
pod 'PromiseKit'
|
||||
pod 'AdaptiveCards'
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
# Sample App for running the Microsoft Graph notifications client library in your iOS application
|
||||
|
||||
## Getting Started
|
||||
|
||||
### Prerequisites
|
||||
|
||||
1. Have xCode and Cocoapods installed installed. More details [here](https://cocoapods.org/)
|
||||
|
||||
### Building the sample
|
||||
1. ``pod install`` (from directory of podfile)
|
||||
2. ``build from xCode``
|
||||
|
||||
### Running the sample
|
||||
1. Build the sample (if is not built already).
|
||||
1. Initialize and setup MSAL using the directions given [here](https://github.com/AzureAD/microsoft-authentication-library-for-objc)
|
||||
1. Set the following values:
|
||||
- ``APPLICATION_CLIENT_ID`` in Secrets.h: this is the client ID of your Azure AD client app
|
||||
- ``APP_HOST_NAME`` in secrets.h: this is the "cross-device domain name" that you have registered
|
||||
and verified in your Cross-Device App registration in Partner Center (https://partner.microsoft.com/dashboard )
|
||||
2. Sign in with an Azure AD or MSA account.
|
||||
3. Click Subscribe, then grant permissions for the iOS app to read and write notifications.
|
||||
4. Click the other buttons to exercise the various functions.
|
||||
5. Post a new notification from Graph explorer and see a notification popup. Click the popup to be redirected to https://docs.microsoft.com/en-us/graph/notifications-concept-overview
|
||||
## Other tips
|
||||
|
||||
1. Getting duplicate push notifications? This is a known server-side issue in some cases.
|
||||
See the [README for the client itself](https://www.npmjs.com/package/@microsoft/user-notifications-client) to learn more. Look for the text starting with:
|
||||
> userNotificationApiImpl.processPushNotificationAsync(notificationPayload) may call back to the Graph notification server to fetch notification data
|
||||
|
||||
1. To look at the logs of the sample app and the client library, the best way to do it is to set the xCode environment variable
|
||||
``CFNETWORK_DIAGNOSTICS`` = 3
|
||||
|
Загрузка…
Ссылка в новой задаче