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-19716] Support contact icon in UIApplicationShortcuts #7299

Merged
merged 2 commits into from
Oct 14, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
71 changes: 67 additions & 4 deletions apidoc/Titanium/UI/iOS/ApplicationShortcuts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ methods:
type: String

examples:
- title: Example app.js
- title: Full example (get shortcuts, add shortcuts, remove shortcuts, check shortcuts).
example: |
The following code excerpt demonstrates

Expand Down Expand Up @@ -162,6 +162,68 @@ examples:

win.open();

- title: Add a <Titianium.Contact.Person> as icon.
example: |
Ti.App.iOS.addEventListener("shortcutitemclick", function(e){
Ti.API.info("shortcutitemclick Event Fired");
Ti.API.info("person:" + JSON.stringify(e.userInfo.person));
});

var win = Titanium.UI.createWindow({
title:'Test', backgroundColor:'#fff', layout:"vertical"
});

var btn1 = Ti.UI.createButton({
top: 50, height:45, title:"Add Ti.Contacts Application Shortcut"
});
win.add(btn1);

btn1.addEventListener("click", function() {
if(!Ti.Contacts.hasContactsPermissions()) {
Ti.Contacts.requestContactsPermissions(function(e) {
if(e.success) {
createShortcut();
}
})
} else {
createShortcut();
}
});

var btn2 = Ti.UI.createButton({
top: 10, height:45, title:"Remove Ti.Contacts Application Shortcut"
});
win.add(btn2);

btn2.addEventListener("click", function(){
var appShortcuts = Ti.UI.iOS.createApplicationShortcuts();
appShortcuts.removeDynamicShortcut("contact_us");
});

function createShortcut() {
Ti.Contacts.showContacts({
selectedPerson: function(e) {
var person = e.person;

var appShortcuts = Ti.UI.iOS.createApplicationShortcuts();
appShortcuts.addDynamicShortcut({
itemtype:"contact_us",
title: person.fullName,
subtitle: "Tap to call",
icon: person,
userInfo: {
person: {
firstName: person.firstName,
lastName: person.lastName
}
}
});
}
});
}

win.open();

---
name: ShortcutParams
summary: Dictionary of options for <Titanium.UI.iOS.addDynamicShortcut>.
Expand All @@ -185,8 +247,9 @@ properties:

- name: icon
summary: |
The icon to be displayed on the application shortcut, for example <Titanium.UI.iOS.SHORTCUT_ICON_TYPE_COMPOSE>.
Note: You can also use a local image specified by the image path.
type: Number
The icon to be displayed on the application shortcut. You can either use one of the contastants like
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spelling: not contestants, but constants

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed your comment in the latest commit, thanks!

<Titanium.UI.iOS.SHORTCUT_ICON_TYPE_COMPOSE>, a local image specified by the image path or a reference to a
<Titanium.Contacts.Person>.
type: [Number,String,Titanium.Contacts.Person]
constants: Titanium.UI.iOS.SHORTCUT_ICON_TYPE_*
optional: true
1 change: 1 addition & 0 deletions iphone/Classes/TiContactsPerson.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
-(CNSaveRequest*)getSaveRequestForAddToGroup: (CNMutableGroup*) group;
-(CNSaveRequest*)getSaveRequestForRemoveFromGroup: (CNMutableGroup*) group;
-(void)updateiOS9ContactProperties;
-(CNMutableContact*)nativePerson;
#endif
-(id)valueForUndefinedKey:(NSString *)key;
-(NSString*)fullName;
Expand Down
7 changes: 7 additions & 0 deletions iphone/Classes/TiContactsPerson.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ -(NSString*)apiName
return @"Ti.Contacts.Person";
}

#if IS_XCODE_7
-(CNMutableContact*)nativePerson
{
return person;
}
#endif

#if IS_XCODE_7
-(NSDictionary*)getiOS9ContactProperties: (CNMutableContact*) contact
{
Expand Down
7 changes: 7 additions & 0 deletions iphone/Classes/TiUIiOSApplicationShortcutsProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#ifdef USE_TI_UIIOSAPPLICATIONSHORTCUTS
#import "TiUIiOSApplicationShortcutsProxy.h"
#import "TiUtils.h"
#import "TiContactsPerson.h"
#import <ContactsUI/ContactsUI.h>
#import <CommonCrypto/CommonDigest.h>

@implementation TiUIiOSApplicationShortcutsProxy
Expand Down Expand Up @@ -204,6 +206,11 @@ -(void)addDynamicShortcut:(id)args

-(UIApplicationShortcutIcon*)findIcon:(id)value
{
if([value isKindOfClass:[TiContactsPerson class]]) {
ENSURE_TYPE(value, TiContactsPerson);
return [UIApplicationShortcutIcon iconWithContact: [(TiContactsPerson*)value nativePerson]];
}

if ([value isKindOfClass:[UIApplicationShortcutIcon class]]) {
return (UIApplicationShortcutIcon*)value;
}
Expand Down