|
| 1 | +// |
| 2 | +// LPInbox.h |
| 3 | +// Leanplum |
| 4 | +// |
| 5 | +// Created by Aleksandar Gyorev on 05/08/15. |
| 6 | +// Copyright (c) 2015 Leanplum. All rights reserved. |
| 7 | +// |
| 8 | +// |
| 9 | + |
| 10 | +#import <Foundation/Foundation.h> |
| 11 | + |
| 12 | +#pragma mark - LPInboxMessage interface |
| 13 | + |
| 14 | +@interface LPInboxMessage : NSObject <NSCoding> |
| 15 | + |
| 16 | +#pragma mark - LPInboxMessage methods |
| 17 | + |
| 18 | +/** |
| 19 | + * Returns the message identifier of the inbox message. |
| 20 | + */ |
| 21 | +- (NSString *)messageId; |
| 22 | + |
| 23 | +/** |
| 24 | + * Returns the title of the inbox message. |
| 25 | + */ |
| 26 | +- (NSString *)title; |
| 27 | + |
| 28 | +/** |
| 29 | + * Returns the subtitle of the inbox message. |
| 30 | + */ |
| 31 | +- (NSString *)subtitle; |
| 32 | + |
| 33 | +/** |
| 34 | + * Returns the image path of the inbox message. Can be nil. |
| 35 | + * Use with [UIImage contentsOfFile:]. |
| 36 | + */ |
| 37 | +- (NSString *)imageFilePath; |
| 38 | + |
| 39 | +/** |
| 40 | + * Returns the image URL of the inbox message. |
| 41 | + * You can safely use this with prefetching enabled. |
| 42 | + * It will return the file URL path instead if the image is in cache. |
| 43 | + */ |
| 44 | +- (NSURL *)imageURL; |
| 45 | + |
| 46 | +/** |
| 47 | + * Returns the data of the inbox message. Advanced use only. |
| 48 | + */ |
| 49 | +- (NSDictionary *)data; |
| 50 | + |
| 51 | +/** |
| 52 | + * Returns the delivery timestamp of the inbox message. |
| 53 | + */ |
| 54 | +- (NSDate *)deliveryTimestamp; |
| 55 | + |
| 56 | +/** |
| 57 | + * Return the expiration timestamp of the inbox message. |
| 58 | + */ |
| 59 | +- (NSDate *)expirationTimestamp; |
| 60 | + |
| 61 | +/** |
| 62 | + * Returns YES if the inbox message is read. |
| 63 | + */ |
| 64 | +- (BOOL)isRead; |
| 65 | + |
| 66 | +/** |
| 67 | + * Read the inbox message, marking it as read and invoking its open action. |
| 68 | + */ |
| 69 | +- (void)read; |
| 70 | + |
| 71 | +/** |
| 72 | + * Remove the inbox message from the inbox. |
| 73 | + */ |
| 74 | +- (void)remove; |
| 75 | + |
| 76 | +@end |
| 77 | + |
| 78 | +#pragma mark - LPInbox interface |
| 79 | + |
| 80 | +/** |
| 81 | + * This block is used when you define a callback. |
| 82 | + */ |
| 83 | +typedef void (^LeanplumInboxChangedBlock)(); |
| 84 | + |
| 85 | +@interface LPInbox : NSObject |
| 86 | + |
| 87 | +#pragma mark - LPInbox methods |
| 88 | + |
| 89 | +/** |
| 90 | + * Returns the number of all inbox messages on the device. |
| 91 | + */ |
| 92 | +- (NSUInteger)count; |
| 93 | + |
| 94 | +/** |
| 95 | + * Returns the number of the unread inbox messages on the device. |
| 96 | + */ |
| 97 | +- (NSUInteger)unreadCount; |
| 98 | + |
| 99 | +/** |
| 100 | + * Returns the identifiers of all inbox messages on the device sorted in ascending |
| 101 | + * chronological order, i.e. the id of the oldest message is the first one, and the most |
| 102 | + * recent one is the last one in the array. |
| 103 | + */ |
| 104 | +- (NSArray *)messagesIds; |
| 105 | + |
| 106 | +/** |
| 107 | + * Returns an array containing all of the inbox messages (as LPInboxMessage objects) |
| 108 | + * on the device, sorted in ascending chronological order, i.e. the oldest message is the |
| 109 | + * first one, and the most recent one is the last one in the array. |
| 110 | + */ |
| 111 | +- (NSArray *)allMessages; |
| 112 | + |
| 113 | +/** |
| 114 | + * Returns an array containing all of the unread inbox messages on the device, sorted |
| 115 | + * in ascending chronological order, i.e. the oldest message is the first one, and the |
| 116 | + * most recent one is the last one in the array. |
| 117 | + */ |
| 118 | +- (NSArray *)unreadMessages; |
| 119 | + |
| 120 | +/** |
| 121 | + * Returns the inbox messages associated with the given messageId identifier. |
| 122 | + */ |
| 123 | +- (LPInboxMessage *)messageForId:(NSString *)messageId; |
| 124 | + |
| 125 | +/** |
| 126 | + * Call this method if you don't want Inbox images to be prefetched. |
| 127 | + * Useful if you only want to deal with image URL. |
| 128 | + */ |
| 129 | +- (void)disableImagePrefetching; |
| 130 | + |
| 131 | +/** |
| 132 | + * Block to call when the inbox receive new values from the server. |
| 133 | + * This will be called on start, and also later on if the user is in an experiment |
| 134 | + * that can update in realtime. |
| 135 | + */ |
| 136 | +- (void)onChanged:(LeanplumInboxChangedBlock)block; |
| 137 | + |
| 138 | +/** |
| 139 | + @{ |
| 140 | + * Adds a responder to be executed when an event happens. |
| 141 | + * Uses NSInvocation instead of blocks. |
| 142 | + * @see [Leanplum onStartResponse:] |
| 143 | + */ |
| 144 | +- (void)addInboxChangedResponder:(id)responder withSelector:(SEL)selector; |
| 145 | +- (void)removeInboxChangedResponder:(id)responder withSelector:(SEL)selector; |
| 146 | +/**@}*/ |
| 147 | + |
| 148 | +@end |
| 149 | + |
| 150 | +#pragma mark - LPNewsfeed for backwards compatibility |
| 151 | +@interface LPNewsfeedMessage : LPInboxMessage |
| 152 | + |
| 153 | +@end |
| 154 | + |
| 155 | +typedef void (^LeanplumNewsfeedChangedBlock)(); |
| 156 | + |
| 157 | +@interface LPNewsfeed : NSObject |
| 158 | + |
| 159 | ++ (LPNewsfeed *)sharedState; |
| 160 | +- (NSUInteger)count; |
| 161 | +- (NSUInteger)unreadCount; |
| 162 | +- (NSArray *)messagesIds; |
| 163 | +- (NSArray *)allMessages; |
| 164 | +- (NSArray *)unreadMessages; |
| 165 | +- (void)onChanged:(LeanplumNewsfeedChangedBlock)block; |
| 166 | +- (LPNewsfeedMessage *)messageForId:(NSString *)messageId; |
| 167 | +- (void)addNewsfeedChangedResponder:(id)responder withSelector:(SEL)selector __attribute__((deprecated)); |
| 168 | +- (void)removeNewsfeedChangedResponder:(id)responder withSelector:(SEL)selector __attribute__((deprecated)); |
| 169 | + |
| 170 | +@end |
0 commit comments