Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-17510] iOS 8 - Local Notification Persmissions #5975

Merged
merged 2 commits into from
Aug 25, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
68 changes: 66 additions & 2 deletions apidoc/Titanium/App/iOS/iOS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ since: "1.5"
methods:
- name: cancelAllLocalNotifications
summary: Cancels all scheduled local notifications.

- name: cancelLocalNotification
summary: Cancels a local notification.
parameters:
Expand All @@ -35,7 +35,35 @@ methods:
Parameters used to create the service. Must include a `url` property, to specify the
local JavaScript file to execute when the application is placed in the background.
type: Dictionary


- name: registerForLocalNotifications
summary: Registers the app for local notifications
description: |
Staring in iOS 8 the app _must_ ask the user for permission before using local notifications.
This is done by registering the application to use local notifications, here you can specify
the types of notifications the app will use, such as <Titanium.App.iOS.NOTIFICATION_TYPE_BADGE>,
<Titanium.App.iOS.NOTIFICATION_TYPE_ALERT>, <Titanium.App.iOS.NOTIFICATION_TYPE_SOUND>, and/or
<Titanium.App.iOS.NOTIFICATION_TYPE_NONE>

Ti.App.iOS.registerForLocalNotifications({
types: Ti.App.iOS.NOTIFICATION_TYPE_BADGE |
Ti.App.iOS.NOTIFICATION_TYPE_SOUND |
Ti.App.iOS.NOTIFICATION_TYPE_ALERT
});
Ti.App.addEventListener('paused', function(){
Ti.App.iOS.scheduleLocalNotification({
alertBody: 'Hello!',
alertAction: 'Here!'
});
});
parameters:
- name: types
summary: The types of notifications required by the application separated by a bitwise-OR operator
constants: Titanium.App.iOS.NOTIFICATION_TYPE_*
type: Number
since: 3.4.0
osver: {ios: {min: "8.0"}}

- name: scheduleLocalNotification
summary: Schedule a local notification.
returns:
Expand Down Expand Up @@ -110,6 +138,42 @@ properties:
osver: {ios: {min: "7.0"}}
since: "3.2.0"

- name: NOTIFICATION_TYPE_NONE
summary: |
Use with [registerForLocalNotifications](Titanium.App.iOS.registerForLocalNotifications) method.
The application may not present any UI upon a notification being received.
type: Number
permission: read-only
osver: {ios: {min: "8.0"}}
since: "3.4.0"

- name: NOTIFICATION_TYPE_BADGE
summary: |
Use with [registerForLocalNotifications](Titanium.App.iOS.registerForLocalNotifications) method.
The application may badge its icon upon a notification being received.
type: Number
permission: read-only
osver: {ios: {min: "8.0"}}
since: "3.4.0"

- name: NOTIFICATION_TYPE_SOUND
summary: |
Use with [registerForLocalNotifications](Titanium.App.iOS.registerForLocalNotifications) method.
The application may play a sound upon a notification being received.
type: Number
permission: read-only
osver: {ios: {min: "8.0"}}
since: "3.4.0"

- name: NOTIFICATION_TYPE_ALERT
summary: |
Use with [registerForLocalNotifications](Titanium.App.iOS.registerForLocalNotifications) method.
The application may display an alert upon a notification being received
type: Number
permission: read-only
osver: {ios: {min: "8.0"}}
since: "3.4.0"

events:
- name: notification
summary: Fired when a local notification is received by the application.
Expand Down
44 changes: 44 additions & 0 deletions iphone/Classes/TiAppiOSProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@ -(id)registerBackgroundService:(id)args
return proxy;
}

-(void)registerForLocalNotifications:(id)args
{
if(![TiUtils isIOS8OrGreater]) return;
ENSURE_SINGLE_ARG(args, NSDictionary)
// TODO: Add "categories" when implementing interactive notifications
// NSSet* categories = [NSSet setWithArray: [args objectForKey:@"categories"]];
UIUserNotificationType types = [TiUtils intValue:[args objectForKey:@"types"] def:0];

UIUserNotificationSettings *notif = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:notif];

}
-(id)scheduleLocalNotification:(id)args
{
ENSURE_SINGLE_ARG(args,NSDictionary);
Expand Down Expand Up @@ -326,6 +338,38 @@ -(NSNumber*)BACKGROUNDFETCHINTERVAL_NEVER {
return nil;
}

-(NSNumber*)NOTIFICATION_TYPE_NONE
{
if ([TiUtils isIOS8OrGreater]) {
return NUMINT(UIUserNotificationTypeNone);
}
return NUMINT(0);
}

-(NSNumber*)NOTIFICATION_TYPE_BADGE
{
if ([TiUtils isIOS8OrGreater]) {
return NUMINT(UIUserNotificationTypeBadge);
}
return NUMINT(0);
}

-(NSNumber*)NOTIFICATION_TYPE_SOUND
{
if ([TiUtils isIOS8OrGreater]) {
return NUMINT(UIUserNotificationTypeSound);
}
return NUMINT(0);
}

-(NSNumber*)NOTIFICATION_TYPE_ALERT
{
if ([TiUtils isIOS8OrGreater]) {
return NUMINT(UIUserNotificationTypeAlert);
}
return NUMINT(0);
}

MAKE_SYSTEM_STR(EVENT_ACCESSIBILITY_LAYOUT_CHANGED,@"accessibilitylayoutchanged");
MAKE_SYSTEM_STR(EVENT_ACCESSIBILITY_SCREEN_CHANGED,@"accessibilityscreenchanged");

Expand Down